# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376776 | 2021-03-12T03:41:33 Z | daniel920712 | Mergers (JOI19_mergers) | C++14 | 447 ms | 262148 KB |
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <set> #include <vector> using namespace std; set < int > a,b; set < pair < int , int > > road; int now=0; vector < int > Next[500005]; int color[500005]; int deg[500005]={0}; vector < int > con[500005]; int sum[500005]={0}; int M; void F(int here,int fa,int x) { int i,j; con[here][color[here]]++; sum[color[here]]++; for(auto i:Next[here]) { if(i==fa) continue; F(i,here,x); for(j=1;j<=M;j++) con[here][j]+=con[i][j]; } } void F3(int here,int fa,int x) { int ok=1,i,j; for(auto i:Next[here]) { ok=1; if(i==fa) continue; F3(i,here,x); for(j=1;j<=M;j++) { if(con[i][j]>0&&con[i][j]<sum[j]) { //printf("%d %d %d %d %d\n",here,i,j,con[i][j],sum[j]); ok=0; } } if(ok) { //printf("%d %d\n",here,i); road.insert(make_pair(here,i)); road.insert(make_pair(i,here)); } } } void F2(int here,int fa,int xx) { for(auto i:Next[here]) { if(i==fa) continue; if(road.find(make_pair(here,i))!=road.end()) { now++; deg[xx]++; deg[now]++; F2(i,here,now); } else F2(i,here,xx); } } int main() { int N,i,j,x,y,xx=0,ok=1; scanf("%d %d",&N,&M); for(i=1;i<N;i++) { scanf("%d %d",&x,&y); Next[x].push_back(y); Next[y].push_back(x); } for(i=1;i<=N;i++) { scanf("%d",&color[i]); for(j=0;j<=M;j++) con[i].push_back(0); } F(1,-1,0); F3(1,-1,0); now=0; F2(1,-1,0); for(i=0;i<=now;i++) if(deg[i]==1) xx++; if(xx==1) printf("0\n"); else printf("%d\n",(xx+1)/2); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23884 KB | Output is correct |
2 | Correct | 17 ms | 23840 KB | Output is correct |
3 | Correct | 17 ms | 23788 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 18 ms | 23936 KB | Output is correct |
6 | Correct | 23 ms | 23788 KB | Output is correct |
7 | Correct | 16 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 16 ms | 23788 KB | Output is correct |
11 | Correct | 17 ms | 23788 KB | Output is correct |
12 | Correct | 16 ms | 23788 KB | Output is correct |
13 | Correct | 16 ms | 23788 KB | Output is correct |
14 | Correct | 16 ms | 23788 KB | Output is correct |
15 | Correct | 17 ms | 23788 KB | Output is correct |
16 | Correct | 16 ms | 23808 KB | Output is correct |
17 | Correct | 17 ms | 23788 KB | Output is correct |
18 | Correct | 17 ms | 23788 KB | Output is correct |
19 | Correct | 17 ms | 23788 KB | Output is correct |
20 | Correct | 17 ms | 23916 KB | Output is correct |
21 | Correct | 17 ms | 23788 KB | Output is correct |
22 | Correct | 19 ms | 23788 KB | Output is correct |
23 | Correct | 17 ms | 23916 KB | Output is correct |
24 | Correct | 17 ms | 23788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23884 KB | Output is correct |
2 | Correct | 17 ms | 23840 KB | Output is correct |
3 | Correct | 17 ms | 23788 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 18 ms | 23936 KB | Output is correct |
6 | Correct | 23 ms | 23788 KB | Output is correct |
7 | Correct | 16 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 16 ms | 23788 KB | Output is correct |
11 | Correct | 17 ms | 23788 KB | Output is correct |
12 | Correct | 16 ms | 23788 KB | Output is correct |
13 | Correct | 16 ms | 23788 KB | Output is correct |
14 | Correct | 16 ms | 23788 KB | Output is correct |
15 | Correct | 17 ms | 23788 KB | Output is correct |
16 | Correct | 16 ms | 23808 KB | Output is correct |
17 | Correct | 17 ms | 23788 KB | Output is correct |
18 | Correct | 17 ms | 23788 KB | Output is correct |
19 | Correct | 17 ms | 23788 KB | Output is correct |
20 | Correct | 17 ms | 23916 KB | Output is correct |
21 | Correct | 17 ms | 23788 KB | Output is correct |
22 | Correct | 19 ms | 23788 KB | Output is correct |
23 | Correct | 17 ms | 23916 KB | Output is correct |
24 | Correct | 17 ms | 23788 KB | Output is correct |
25 | Correct | 17 ms | 23788 KB | Output is correct |
26 | Correct | 77 ms | 48288 KB | Output is correct |
27 | Correct | 21 ms | 24812 KB | Output is correct |
28 | Correct | 107 ms | 71532 KB | Output is correct |
29 | Correct | 97 ms | 71464 KB | Output is correct |
30 | Correct | 25 ms | 26988 KB | Output is correct |
31 | Correct | 17 ms | 23788 KB | Output is correct |
32 | Correct | 106 ms | 71404 KB | Output is correct |
33 | Correct | 17 ms | 23788 KB | Output is correct |
34 | Correct | 21 ms | 24812 KB | Output is correct |
35 | Correct | 106 ms | 71576 KB | Output is correct |
36 | Correct | 21 ms | 24812 KB | Output is correct |
37 | Correct | 61 ms | 48108 KB | Output is correct |
38 | Correct | 17 ms | 23916 KB | Output is correct |
39 | Correct | 59 ms | 48108 KB | Output is correct |
40 | Correct | 19 ms | 24044 KB | Output is correct |
41 | Correct | 20 ms | 24172 KB | Output is correct |
42 | Correct | 59 ms | 48108 KB | Output is correct |
43 | Correct | 19 ms | 24300 KB | Output is correct |
44 | Correct | 17 ms | 23916 KB | Output is correct |
45 | Correct | 99 ms | 70124 KB | Output is correct |
46 | Correct | 59 ms | 47852 KB | Output is correct |
47 | Correct | 17 ms | 23916 KB | Output is correct |
48 | Correct | 38 ms | 36076 KB | Output is correct |
49 | Correct | 108 ms | 71532 KB | Output is correct |
50 | Correct | 106 ms | 71656 KB | Output is correct |
51 | Correct | 38 ms | 36076 KB | Output is correct |
52 | Correct | 22 ms | 24812 KB | Output is correct |
53 | Correct | 58 ms | 48108 KB | Output is correct |
54 | Correct | 21 ms | 24812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23884 KB | Output is correct |
2 | Correct | 17 ms | 23840 KB | Output is correct |
3 | Correct | 17 ms | 23788 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 18 ms | 23936 KB | Output is correct |
6 | Correct | 23 ms | 23788 KB | Output is correct |
7 | Correct | 16 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 16 ms | 23788 KB | Output is correct |
11 | Correct | 17 ms | 23788 KB | Output is correct |
12 | Correct | 16 ms | 23788 KB | Output is correct |
13 | Correct | 16 ms | 23788 KB | Output is correct |
14 | Correct | 16 ms | 23788 KB | Output is correct |
15 | Correct | 17 ms | 23788 KB | Output is correct |
16 | Correct | 16 ms | 23808 KB | Output is correct |
17 | Correct | 17 ms | 23788 KB | Output is correct |
18 | Correct | 17 ms | 23788 KB | Output is correct |
19 | Correct | 17 ms | 23788 KB | Output is correct |
20 | Correct | 17 ms | 23916 KB | Output is correct |
21 | Correct | 17 ms | 23788 KB | Output is correct |
22 | Correct | 19 ms | 23788 KB | Output is correct |
23 | Correct | 17 ms | 23916 KB | Output is correct |
24 | Correct | 17 ms | 23788 KB | Output is correct |
25 | Correct | 19 ms | 23788 KB | Output is correct |
26 | Correct | 208 ms | 54800 KB | Output is correct |
27 | Correct | 229 ms | 54892 KB | Output is correct |
28 | Correct | 23 ms | 24812 KB | Output is correct |
29 | Correct | 15 ms | 23788 KB | Output is correct |
30 | Correct | 21 ms | 23788 KB | Output is correct |
31 | Correct | 235 ms | 54892 KB | Output is correct |
32 | Correct | 18 ms | 24960 KB | Output is correct |
33 | Correct | 311 ms | 63596 KB | Output is correct |
34 | Correct | 244 ms | 54880 KB | Output is correct |
35 | Correct | 23 ms | 24784 KB | Output is correct |
36 | Correct | 267 ms | 55788 KB | Output is correct |
37 | Correct | 22 ms | 24044 KB | Output is correct |
38 | Correct | 31 ms | 24172 KB | Output is correct |
39 | Correct | 217 ms | 55140 KB | Output is correct |
40 | Correct | 18 ms | 24300 KB | Output is correct |
41 | Correct | 152 ms | 31340 KB | Output is correct |
42 | Correct | 265 ms | 57708 KB | Output is correct |
43 | Correct | 18 ms | 23916 KB | Output is correct |
44 | Correct | 171 ms | 40428 KB | Output is correct |
45 | Correct | 247 ms | 59500 KB | Output is correct |
46 | Correct | 21 ms | 24812 KB | Output is correct |
47 | Correct | 24 ms | 24812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 205 ms | 54376 KB | Output is correct |
2 | Runtime error | 447 ms | 262148 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23884 KB | Output is correct |
2 | Correct | 17 ms | 23840 KB | Output is correct |
3 | Correct | 17 ms | 23788 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 18 ms | 23936 KB | Output is correct |
6 | Correct | 23 ms | 23788 KB | Output is correct |
7 | Correct | 16 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 16 ms | 23788 KB | Output is correct |
10 | Correct | 16 ms | 23788 KB | Output is correct |
11 | Correct | 17 ms | 23788 KB | Output is correct |
12 | Correct | 16 ms | 23788 KB | Output is correct |
13 | Correct | 16 ms | 23788 KB | Output is correct |
14 | Correct | 16 ms | 23788 KB | Output is correct |
15 | Correct | 17 ms | 23788 KB | Output is correct |
16 | Correct | 16 ms | 23808 KB | Output is correct |
17 | Correct | 17 ms | 23788 KB | Output is correct |
18 | Correct | 17 ms | 23788 KB | Output is correct |
19 | Correct | 17 ms | 23788 KB | Output is correct |
20 | Correct | 17 ms | 23916 KB | Output is correct |
21 | Correct | 17 ms | 23788 KB | Output is correct |
22 | Correct | 19 ms | 23788 KB | Output is correct |
23 | Correct | 17 ms | 23916 KB | Output is correct |
24 | Correct | 17 ms | 23788 KB | Output is correct |
25 | Correct | 17 ms | 23788 KB | Output is correct |
26 | Correct | 77 ms | 48288 KB | Output is correct |
27 | Correct | 21 ms | 24812 KB | Output is correct |
28 | Correct | 107 ms | 71532 KB | Output is correct |
29 | Correct | 97 ms | 71464 KB | Output is correct |
30 | Correct | 25 ms | 26988 KB | Output is correct |
31 | Correct | 17 ms | 23788 KB | Output is correct |
32 | Correct | 106 ms | 71404 KB | Output is correct |
33 | Correct | 17 ms | 23788 KB | Output is correct |
34 | Correct | 21 ms | 24812 KB | Output is correct |
35 | Correct | 106 ms | 71576 KB | Output is correct |
36 | Correct | 21 ms | 24812 KB | Output is correct |
37 | Correct | 61 ms | 48108 KB | Output is correct |
38 | Correct | 17 ms | 23916 KB | Output is correct |
39 | Correct | 59 ms | 48108 KB | Output is correct |
40 | Correct | 19 ms | 24044 KB | Output is correct |
41 | Correct | 20 ms | 24172 KB | Output is correct |
42 | Correct | 59 ms | 48108 KB | Output is correct |
43 | Correct | 19 ms | 24300 KB | Output is correct |
44 | Correct | 17 ms | 23916 KB | Output is correct |
45 | Correct | 99 ms | 70124 KB | Output is correct |
46 | Correct | 59 ms | 47852 KB | Output is correct |
47 | Correct | 17 ms | 23916 KB | Output is correct |
48 | Correct | 38 ms | 36076 KB | Output is correct |
49 | Correct | 108 ms | 71532 KB | Output is correct |
50 | Correct | 106 ms | 71656 KB | Output is correct |
51 | Correct | 38 ms | 36076 KB | Output is correct |
52 | Correct | 22 ms | 24812 KB | Output is correct |
53 | Correct | 58 ms | 48108 KB | Output is correct |
54 | Correct | 21 ms | 24812 KB | Output is correct |
55 | Correct | 19 ms | 23788 KB | Output is correct |
56 | Correct | 208 ms | 54800 KB | Output is correct |
57 | Correct | 229 ms | 54892 KB | Output is correct |
58 | Correct | 23 ms | 24812 KB | Output is correct |
59 | Correct | 15 ms | 23788 KB | Output is correct |
60 | Correct | 21 ms | 23788 KB | Output is correct |
61 | Correct | 235 ms | 54892 KB | Output is correct |
62 | Correct | 18 ms | 24960 KB | Output is correct |
63 | Correct | 311 ms | 63596 KB | Output is correct |
64 | Correct | 244 ms | 54880 KB | Output is correct |
65 | Correct | 23 ms | 24784 KB | Output is correct |
66 | Correct | 267 ms | 55788 KB | Output is correct |
67 | Correct | 22 ms | 24044 KB | Output is correct |
68 | Correct | 31 ms | 24172 KB | Output is correct |
69 | Correct | 217 ms | 55140 KB | Output is correct |
70 | Correct | 18 ms | 24300 KB | Output is correct |
71 | Correct | 152 ms | 31340 KB | Output is correct |
72 | Correct | 265 ms | 57708 KB | Output is correct |
73 | Correct | 18 ms | 23916 KB | Output is correct |
74 | Correct | 171 ms | 40428 KB | Output is correct |
75 | Correct | 247 ms | 59500 KB | Output is correct |
76 | Correct | 21 ms | 24812 KB | Output is correct |
77 | Correct | 24 ms | 24812 KB | Output is correct |
78 | Correct | 205 ms | 54376 KB | Output is correct |
79 | Runtime error | 447 ms | 262148 KB | Execution killed with signal 9 |
80 | Halted | 0 ms | 0 KB | - |