# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
245452 | 2020-07-06T13:20:55 Z | TadijaSebez | 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) | C++11 | 1365 ms | 72056 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back 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 Mrg(int A,int B){ if(all[A].empty())return B; if(all[B].empty())return A; Del(A);Del(B); E[B].erase(A); R[A].erase(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(); vector<int> nxt; for(int x:E[A]){ if(R[B].count(x))nxt.pb(x); R[x].erase(A); if(!E[B].count(x)){ E[B].insert(x); R[x].insert(B); } } E[A].clear(); for(int x:R[A]){ if(E[B].count(x))nxt.pb(x); E[x].erase(A); if(!R[B].count(x)){ R[B].insert(x); E[x].insert(B); } } R[A].clear(); Add(B); sort(nxt.begin(),nxt.end()); nxt.erase(unique(nxt.begin(),nxt.end()),nxt.end()); for(int x:nxt){ if(B!=x)B=Mrg(B,x); } return B; } int main(){ int n,m;scanf("%i %i",&n,&m); for(int i=1;i<=n;i++)all[i].insert(i),my[i]=i; for(int i=1;i<=m;i++){ int u,v;scanf("%i %i",&u,&v); int A=my[u],B=my[v]; if(A!=B){ if(E[B].count(A)){ Mrg(A,B); }else{ Del(B); in[B].insert(u); E[A].insert(B); R[B].insert(A); Add(B); } } printf("%lld\n",ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 19072 KB | Output is correct |
2 | Correct | 15 ms | 19200 KB | Output is correct |
3 | Correct | 16 ms | 19200 KB | Output is correct |
4 | Correct | 18 ms | 19200 KB | Output is correct |
5 | Correct | 15 ms | 19200 KB | Output is correct |
6 | Correct | 16 ms | 19200 KB | Output is correct |
7 | Correct | 16 ms | 19200 KB | Output is correct |
8 | Correct | 16 ms | 19200 KB | Output is correct |
9 | Correct | 16 ms | 19200 KB | Output is correct |
10 | Correct | 15 ms | 19072 KB | Output is correct |
11 | Correct | 18 ms | 19072 KB | Output is correct |
12 | Correct | 15 ms | 19072 KB | Output is correct |
13 | Correct | 18 ms | 19072 KB | Output is correct |
14 | Correct | 15 ms | 19072 KB | Output is correct |
15 | Correct | 15 ms | 19072 KB | Output is correct |
16 | Correct | 16 ms | 19072 KB | Output is correct |
17 | Correct | 19 ms | 19200 KB | Output is correct |
18 | Correct | 16 ms | 19200 KB | Output is correct |
19 | Correct | 19 ms | 19072 KB | Output is correct |
20 | Correct | 16 ms | 19200 KB | Output is correct |
21 | Correct | 16 ms | 19200 KB | Output is correct |
22 | Correct | 15 ms | 19072 KB | Output is correct |
23 | Correct | 18 ms | 19204 KB | Output is correct |
24 | Correct | 16 ms | 19200 KB | Output is correct |
25 | Correct | 16 ms | 19200 KB | Output is correct |
26 | Correct | 18 ms | 19072 KB | Output is correct |
27 | Correct | 17 ms | 19200 KB | Output is correct |
28 | Correct | 15 ms | 19072 KB | Output is correct |
29 | Correct | 18 ms | 19072 KB | Output is correct |
30 | Correct | 15 ms | 19072 KB | Output is correct |
31 | Correct | 16 ms | 19200 KB | Output is correct |
32 | Correct | 16 ms | 19072 KB | Output is correct |
33 | Correct | 16 ms | 19200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 19072 KB | Output is correct |
2 | Correct | 15 ms | 19200 KB | Output is correct |
3 | Correct | 16 ms | 19200 KB | Output is correct |
4 | Correct | 18 ms | 19200 KB | Output is correct |
5 | Correct | 15 ms | 19200 KB | Output is correct |
6 | Correct | 16 ms | 19200 KB | Output is correct |
7 | Correct | 16 ms | 19200 KB | Output is correct |
8 | Correct | 16 ms | 19200 KB | Output is correct |
9 | Correct | 16 ms | 19200 KB | Output is correct |
10 | Correct | 15 ms | 19072 KB | Output is correct |
11 | Correct | 18 ms | 19072 KB | Output is correct |
12 | Correct | 15 ms | 19072 KB | Output is correct |
13 | Correct | 18 ms | 19072 KB | Output is correct |
14 | Correct | 15 ms | 19072 KB | Output is correct |
15 | Correct | 15 ms | 19072 KB | Output is correct |
16 | Correct | 16 ms | 19072 KB | Output is correct |
17 | Correct | 19 ms | 19200 KB | Output is correct |
18 | Correct | 16 ms | 19200 KB | Output is correct |
19 | Correct | 19 ms | 19072 KB | Output is correct |
20 | Correct | 16 ms | 19200 KB | Output is correct |
21 | Correct | 16 ms | 19200 KB | Output is correct |
22 | Correct | 15 ms | 19072 KB | Output is correct |
23 | Correct | 18 ms | 19204 KB | Output is correct |
24 | Correct | 16 ms | 19200 KB | Output is correct |
25 | Correct | 16 ms | 19200 KB | Output is correct |
26 | Correct | 18 ms | 19072 KB | Output is correct |
27 | Correct | 17 ms | 19200 KB | Output is correct |
28 | Correct | 15 ms | 19072 KB | Output is correct |
29 | Correct | 18 ms | 19072 KB | Output is correct |
30 | Correct | 15 ms | 19072 KB | Output is correct |
31 | Correct | 16 ms | 19200 KB | Output is correct |
32 | Correct | 16 ms | 19072 KB | Output is correct |
33 | Correct | 16 ms | 19200 KB | Output is correct |
34 | Correct | 21 ms | 19328 KB | Output is correct |
35 | Correct | 142 ms | 24896 KB | Output is correct |
36 | Correct | 168 ms | 27744 KB | Output is correct |
37 | Correct | 179 ms | 27896 KB | Output is correct |
38 | Correct | 179 ms | 27560 KB | Output is correct |
39 | Correct | 19 ms | 19328 KB | Output is correct |
40 | Correct | 20 ms | 19456 KB | Output is correct |
41 | Correct | 20 ms | 19456 KB | Output is correct |
42 | Correct | 18 ms | 19328 KB | Output is correct |
43 | Correct | 19 ms | 19488 KB | Output is correct |
44 | Correct | 19 ms | 19456 KB | Output is correct |
45 | Correct | 22 ms | 19328 KB | Output is correct |
46 | Correct | 18 ms | 19328 KB | Output is correct |
47 | Correct | 19 ms | 19456 KB | Output is correct |
48 | Correct | 20 ms | 19456 KB | Output is correct |
49 | Correct | 36 ms | 20096 KB | Output is correct |
50 | Correct | 174 ms | 27880 KB | Output is correct |
51 | Correct | 24 ms | 19712 KB | Output is correct |
52 | Correct | 150 ms | 26232 KB | Output is correct |
53 | Correct | 27 ms | 20096 KB | Output is correct |
54 | Correct | 155 ms | 27128 KB | Output is correct |
55 | Correct | 23 ms | 19840 KB | Output is correct |
56 | Correct | 22 ms | 19840 KB | Output is correct |
57 | Correct | 25 ms | 20224 KB | Output is correct |
58 | Correct | 29 ms | 20096 KB | Output is correct |
59 | Correct | 21 ms | 19328 KB | Output is correct |
60 | Correct | 130 ms | 24312 KB | Output is correct |
61 | Correct | 20 ms | 19456 KB | Output is correct |
62 | Correct | 157 ms | 27384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 19072 KB | Output is correct |
2 | Correct | 15 ms | 19200 KB | Output is correct |
3 | Correct | 16 ms | 19200 KB | Output is correct |
4 | Correct | 18 ms | 19200 KB | Output is correct |
5 | Correct | 15 ms | 19200 KB | Output is correct |
6 | Correct | 16 ms | 19200 KB | Output is correct |
7 | Correct | 16 ms | 19200 KB | Output is correct |
8 | Correct | 16 ms | 19200 KB | Output is correct |
9 | Correct | 16 ms | 19200 KB | Output is correct |
10 | Correct | 15 ms | 19072 KB | Output is correct |
11 | Correct | 18 ms | 19072 KB | Output is correct |
12 | Correct | 15 ms | 19072 KB | Output is correct |
13 | Correct | 18 ms | 19072 KB | Output is correct |
14 | Correct | 15 ms | 19072 KB | Output is correct |
15 | Correct | 15 ms | 19072 KB | Output is correct |
16 | Correct | 16 ms | 19072 KB | Output is correct |
17 | Correct | 19 ms | 19200 KB | Output is correct |
18 | Correct | 16 ms | 19200 KB | Output is correct |
19 | Correct | 19 ms | 19072 KB | Output is correct |
20 | Correct | 16 ms | 19200 KB | Output is correct |
21 | Correct | 16 ms | 19200 KB | Output is correct |
22 | Correct | 15 ms | 19072 KB | Output is correct |
23 | Correct | 18 ms | 19204 KB | Output is correct |
24 | Correct | 16 ms | 19200 KB | Output is correct |
25 | Correct | 16 ms | 19200 KB | Output is correct |
26 | Correct | 18 ms | 19072 KB | Output is correct |
27 | Correct | 17 ms | 19200 KB | Output is correct |
28 | Correct | 15 ms | 19072 KB | Output is correct |
29 | Correct | 18 ms | 19072 KB | Output is correct |
30 | Correct | 15 ms | 19072 KB | Output is correct |
31 | Correct | 16 ms | 19200 KB | Output is correct |
32 | Correct | 16 ms | 19072 KB | Output is correct |
33 | Correct | 16 ms | 19200 KB | Output is correct |
34 | Correct | 21 ms | 19328 KB | Output is correct |
35 | Correct | 142 ms | 24896 KB | Output is correct |
36 | Correct | 168 ms | 27744 KB | Output is correct |
37 | Correct | 179 ms | 27896 KB | Output is correct |
38 | Correct | 179 ms | 27560 KB | Output is correct |
39 | Correct | 19 ms | 19328 KB | Output is correct |
40 | Correct | 20 ms | 19456 KB | Output is correct |
41 | Correct | 20 ms | 19456 KB | Output is correct |
42 | Correct | 18 ms | 19328 KB | Output is correct |
43 | Correct | 19 ms | 19488 KB | Output is correct |
44 | Correct | 19 ms | 19456 KB | Output is correct |
45 | Correct | 22 ms | 19328 KB | Output is correct |
46 | Correct | 18 ms | 19328 KB | Output is correct |
47 | Correct | 19 ms | 19456 KB | Output is correct |
48 | Correct | 20 ms | 19456 KB | Output is correct |
49 | Correct | 36 ms | 20096 KB | Output is correct |
50 | Correct | 174 ms | 27880 KB | Output is correct |
51 | Correct | 24 ms | 19712 KB | Output is correct |
52 | Correct | 150 ms | 26232 KB | Output is correct |
53 | Correct | 27 ms | 20096 KB | Output is correct |
54 | Correct | 155 ms | 27128 KB | Output is correct |
55 | Correct | 23 ms | 19840 KB | Output is correct |
56 | Correct | 22 ms | 19840 KB | Output is correct |
57 | Correct | 25 ms | 20224 KB | Output is correct |
58 | Correct | 29 ms | 20096 KB | Output is correct |
59 | Correct | 21 ms | 19328 KB | Output is correct |
60 | Correct | 130 ms | 24312 KB | Output is correct |
61 | Correct | 20 ms | 19456 KB | Output is correct |
62 | Correct | 157 ms | 27384 KB | Output is correct |
63 | Correct | 568 ms | 71920 KB | Output is correct |
64 | Correct | 564 ms | 71928 KB | Output is correct |
65 | Correct | 560 ms | 72056 KB | Output is correct |
66 | Correct | 245 ms | 28636 KB | Output is correct |
67 | Correct | 487 ms | 35040 KB | Output is correct |
68 | Correct | 226 ms | 28664 KB | Output is correct |
69 | Correct | 481 ms | 35816 KB | Output is correct |
70 | Correct | 344 ms | 28664 KB | Output is correct |
71 | Correct | 268 ms | 28664 KB | Output is correct |
72 | Correct | 548 ms | 35196 KB | Output is correct |
73 | Correct | 487 ms | 35156 KB | Output is correct |
74 | Correct | 1185 ms | 46644 KB | Output is correct |
75 | Correct | 722 ms | 41592 KB | Output is correct |
76 | Correct | 951 ms | 46316 KB | Output is correct |
77 | Correct | 989 ms | 46328 KB | Output is correct |
78 | Correct | 304 ms | 34556 KB | Output is correct |
79 | Correct | 517 ms | 37752 KB | Output is correct |
80 | Correct | 303 ms | 34424 KB | Output is correct |
81 | Correct | 538 ms | 37704 KB | Output is correct |
82 | Correct | 1365 ms | 56056 KB | Output is correct |
83 | Correct | 1112 ms | 56312 KB | Output is correct |
84 | Correct | 1110 ms | 65464 KB | Output is correct |
85 | Correct | 1054 ms | 65528 KB | Output is correct |
86 | Correct | 337 ms | 29560 KB | Output is correct |
87 | Correct | 383 ms | 31736 KB | Output is correct |
88 | Correct | 601 ms | 35320 KB | Output is correct |
89 | Correct | 937 ms | 45704 KB | Output is correct |