# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
509873 | 2022-01-14T11:22:33 Z | leinad2 | Making Friends on Joitter is Fun (JOI20_joitter2) | C++17 | 3 ms | 5000 KB |
#include<bits/stdc++.h> using namespace std; int n, m, i, j, k, a, b, sz[100010], par[100010]; long long ans; int Find(int v){return v==par[v]?v:par[v]=Find(par[v]);} multiset<int>adj[100010]; main() { scanf("%d %d", &n, &m); for(i=0;i++<n;)sz[i]=1,par[i]=i; while(m--) { scanf("%d %d", &a, &b); a=Find(a);b=Find(b); if(a!=b) { if(adj[a].find(b)==adj[a].end()) { if(adj[b].find(a)==adj[b].end()) { adj[b].insert(a); ans+=sz[b]; } } else { ans-=1LL*(adj[a].size()-adj[a].count(b))*sz[a]; ans-=1LL*(adj[b].size())*sz[b]; ans+=1LL*sz[a]*sz[b]; ans+=1LL*(sz[b]-adj[a].count(b))*sz[a]; if(adj[a].size()<adj[b].size())swap(adj[a], adj[b]); for(auto p:adj[b])adj[a].insert(p); adj[b].clear(); adj[a].erase(b); sz[a]+=sz[b]; par[b]=a; ans+=1LL*adj[a].size()*sz[a]; } } printf("%lld\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 5000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 5000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 5000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |