From b879ad0a9ccb979532282ba13976c137bef444c6 Mon Sep 17 00:00:00 2001 From: AdsonFS Date: Wed, 3 Jan 2024 12:32:28 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Submiss=C3=A3o=20do=20problema=2001?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- submissions/adsonfs/README.md | 13 +++++++++++++ submissions/adsonfs/problema-1.cpp | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 submissions/adsonfs/README.md create mode 100644 submissions/adsonfs/problema-1.cpp diff --git a/submissions/adsonfs/README.md b/submissions/adsonfs/README.md new file mode 100644 index 0000000..df89beb --- /dev/null +++ b/submissions/adsonfs/README.md @@ -0,0 +1,13 @@ +## Compile with: + +```bash +g++ -std=c++17 submissions/adsonfs/problema-1.cpp -o problema-1.out +``` + +## Run with: + +```bash +./problema-1.out < resources/instances/problem_01/exemplo_01.txt +./problema-1.out < resources/instances/problem_01/exemplo_02.txt +./problema-1.out < resources/instances/problem_01/exemplo_03.txt +``` \ No newline at end of file diff --git a/submissions/adsonfs/problema-1.cpp b/submissions/adsonfs/problema-1.cpp new file mode 100644 index 0000000..7070636 --- /dev/null +++ b/submissions/adsonfs/problema-1.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; + +int main() { + int N, W; + int pd[2667]; + int v[2667], w[2667]; + scanf("%d%d", &N, &W); + for(int i = 0; i < N; i++) scanf("%d%d", w+i, v+i); + for(int j = 0; j <= W; j++) pd[j] = 0; + + for(int i = 0; i < N; i++) + for(int j = W; j >= w[i]; j--) + pd[j] = max(pd[j], pd[j-w[i]] + v[i]); + printf("%d\n", pd[W]); + return 0; +} \ No newline at end of file From ecc6dd7d9088e93a70b91b2c708289dcceea1e41 Mon Sep 17 00:00:00 2001 From: AdsonFS Date: Tue, 9 Jan 2024 21:33:23 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Submiss=C3=A3o=20do=20problema=2002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- submissions/adsonfs/problema-2.cpp | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 submissions/adsonfs/problema-2.cpp diff --git a/submissions/adsonfs/problema-2.cpp b/submissions/adsonfs/problema-2.cpp new file mode 100644 index 0000000..d345d53 --- /dev/null +++ b/submissions/adsonfs/problema-2.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; + +#define rep(i, a, b) for(int i = (a); i < (b); i++) + +int N, M, ans; +vector adj[200]; +int p[200], g[200], G[200], GG[200]; + +int f(int u) { return p[u] == u ? u : p[u] = f(p[u]); } + +int bfs(int s) { + int cnt = N; + priority_queue> pq; + pq.push({G[s], s}); + while(!pq.empty()) { + if(cnt <= ans) return 0; + int u = pq.top().second; + int gg = pq.top().first; + pq.pop(); + if(gg != G[u]) continue; + int U = f(u); + + for(auto v : adj[u]) { + int V = f(v); + if(U == V) continue; + cnt -= (g[u]++ == 1) + (g[v]++ == 1); + G[u]--; G[v]--; + p[V] = U; + if(G[v]) pq.push({G[v], v}); + } + } + return cnt; +} + +int main () { + int u, v; + scanf("%d%d", &N, &M); + rep(i, 0, M) { + scanf("%d%d", &u, &v); + adj[u].push_back(v); + adj[v].push_back(u); + GG[u]++; GG[v]++; + } + + rep(nz, 1, N+1) { + rep(i, 1, 121) { p[i] = i; g[i] = 0; G[i] = GG[i]; } + ans = max(ans, bfs(nz)); + } + printf("%d\n", ans); + return 0; +}