# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1046524 | 2024-08-06T16:11:00 Z | Andrey | Marshmallow Molecules (CCO19_day2problem2) | C++14 | 22 ms | 29788 KB |
#include<bits/stdc++.h> using namespace std; vector<int> dsu(100001); vector<int> haha[100001]; vector<int> bruh[100001]; set<int> idk[100001]; int calc(int a) { int c = a; while(dsu[c] != c) { c = dsu[c]; } int e = a; while(dsu[e] != e) { int d = dsu[e]; dsu[e] = c; e = d; } return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m,a,b; cin >> n >> m; for(int i = 1; i <= n; i++) { dsu[i] = i; } int ans = 0; for(int i = 0; i < m; i++) { cin >> a >> b; haha[a].push_back(b); bruh[b].push_back(a); } for(int i = 1; i <= n; i++) { vector<int> wut(0); int big = -1,p = -1; for(int v: bruh[i]) { int x = calc(v); wut.push_back(x); if(idk[x].size() > big) { big = idk[x].size(); p = x; } } swap(idk[i],idk[p]); sort(wut.begin(),wut.end()); for(int j = 0; j < wut.size(); j++) { if((j == 0 || wut[j] != wut[j-1]) && wut[j] != p) { int c = wut[j]; dsu[c] = i; while(!idk[c].empty()) { int x = *idk[c].lower_bound(-INT_MAX); idk[i].insert(x); idk[c].erase(x); } } } for(int v: haha[i]) { idk[i].insert(v); } idk[i].erase(i); ans+=idk[i].size(); } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 20316 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 20316 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 22 ms | 29788 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 7 ms | 20316 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |