# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
509906 | 2022-01-14T11:42:56 Z | leinad2 | Making Friends on Joitter is Fun (JOI20_joitter2) | C++17 | 3 ms | 4940 KB |
#include<bits/stdc++.h> using namespace std; int n, m, i, j, k, a, b, sz[100010], indeg[100010], par[100010]; long long ans; int Find(int v){return v==par[v]?v:par[v]=Find(par[v]);} map<int, set<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); int x=a, y=b; a=Find(a);b=Find(b); if(a!=b) { if(adj[a].find(b)==adj[a].end()) { if(adj[b][a].find(x)==adj[b][a].end()) { adj[b][a].insert(x); ans+=sz[b]; indeg[b]++; } } else { ans-=1LL*(indeg[a]-(int)adj[a][b].size())*sz[a]; ans-=1LL*(indeg[b])*sz[b]; ans+=1LL*sz[a]*sz[b]; ans+=1LL*(sz[b]-adj[a][b].size())*sz[a]; if(indeg[a]<indeg[b])swap(adj[a], adj[b]); for(auto p:adj[b]) { for(auto q:p.second) adj[a][p.first].insert(q); } adj[b].clear(); indeg[a]-=adj[a][b].size(); adj[a].erase(b); sz[a]+=sz[b]; indeg[a]+=indeg[b]; par[b]=a; ans+=1LL*indeg[a]*sz[a]; } } printf("%lld\n", ans); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 4940 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 4940 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 4940 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |