# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
245412 | 2020-07-06T11:00:09 Z | TadijaSebez | Making Friends on Joitter is Fun (JOI20_joitter2) | C++11 | 15 ms | 19072 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=100050; set<int> in[N],all[N],E[N],R[N]; int my[N]; ll ans; ll Calc(int cmp){ return (ll)all[cmp].size()*((int)all[cmp].size()-1)+(ll)in[cmp].size()*all[cmp].size(); } void Del(int cmp){ ans-=Calc(cmp); } void Add(int cmp){ ans+=Calc(cmp); } int main(){ int n,m;scanf("%i %i",&n,&m); for(int i=1;i<=n;i++)all[i].insert(i),my[i]=i; set<pair<int,int>> edg; for(int i=1;i<=m;i++){ int u,v;scanf("%i %i",&u,&v); if(E[my[v]].count(my[u])){ int A=my[u],B=my[v]; //printf("Mrg %i %i\n",A,B); Del(A);Del(B); if(all[A].size()+in[A].size()+E[A].size()+R[A].size()>all[B].size()+in[B].size()+E[B].size()+R[B].size())swap(A,B); for(int x:all[A]){ if(in[B].count(x))in[B].erase(x); all[B].insert(x); my[x]=B; } all[A].clear(); for(int x:in[A]){ if(!all[B].count(x))in[B].insert(x); } in[A].clear(); for(int x:E[A]){ E[B].insert(x); } E[A].clear(); for(int x:R[A]){ if(E[x].count(A)){ E[x].erase(A); E[x].insert(B); } R[B].insert(x); } R[A].clear(); Add(B); }else{ Del(my[v]); in[my[v]].insert(u); E[my[u]].insert(my[v]); R[my[v]].insert(my[u]); Add(my[v]); } edg.insert({u,v}); printf("%lld\n",ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 19072 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 19072 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 19072 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |