Submission #1046525

#TimeUsernameProblemLanguageResultExecution timeMemory
1046525AndreyMarshmallow Molecules (CCO19_day2problem2)C++14
0 / 25
23 ms28764 KiB
#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; } long long 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; } } if(!wut.empty()) { 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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:45:30: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |             if(idk[x].size() > big) {
      |                ~~~~~~~~~~~~~~^~~~~
Main.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for(int j = 0; j < wut.size(); j++) {
      |                            ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...