# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471365 | 2021-09-08T15:17:31 Z | jazzup | Connecting Supertrees (IOI20_supertrees) | C++14 | 284 ms | 24272 KB |
#include "supertrees.h" #include <vector> #include <cstdio> #include <algorithm> #include <set> using namespace std; int par[1010]; vector<int> heads[1000]; vector<int>::iterator it; int findPar(int n){ if(par[n]==n)return n; return par[n]=findPar(par[n]); } vector<vector<int> > answer; int construct(vector<vector<int> > p) { int n = p.size(); for(int i=0;i<=n;i++){ par[i]=i; } for(int i=0;i<n;i++){ vector<int> vv; answer.push_back(vv); for(int j=0;j<n;j++){ answer[i].push_back(0); } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]!=p[j][i])return 0; } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(p[i][j]==3)return 0; if(p[i][j]==1){ if(findPar(i)<findPar(j)){ par[findPar(j)]=findPar(i); answer[j][findPar(j)]=1; answer[findPar(j)][j]=1; } else if(findPar(i)>findPar(j)){ par[findPar(i)]=findPar(j); answer[i][findPar(i)]=1; answer[findPar(i)][i]=1; } } } } for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ // if(i==j)continue; if(p[i][j]==2){ if(findPar(i)<findPar(j)){ par[findPar(j)]=findPar(i); heads[findPar(i)].push_back(i); heads[findPar(j)].push_back(j); } else if(findPar(i)>findPar(j)){ par[findPar(i)]=findPar(j); heads[findPar(i)].push_back(i); heads[findPar(j)].push_back(j); } } } } for(int h=0;h<n;h++){ sort(heads[h].begin(),heads[h].end()); it=unique(heads[h].begin(),heads[h].end()); heads[h].resize(distance(heads[h].begin(),it)); if(!heads[h].empty()){ for(int i=0;i<heads[h].size()-1;i++){ answer[heads[h][i]][heads[h][i+1]]=1; answer[heads[h][i+1]][heads[h][i]]=1; // printf("%d ",heads[h][i]); } answer[heads[h][heads[h].size()-1]][heads[h][0]]=1; answer[heads[h][0]][heads[h][heads[h].size()-1]]=1; } if(heads[h].size()==2)return 0; // printf("\n"); } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j)continue; else if(p[i][j]==0){ if(findPar(i)==findPar(j)){ return 0; } } } } build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 11 ms | 1296 KB | Output is correct |
7 | Correct | 277 ms | 24084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 11 ms | 1296 KB | Output is correct |
7 | Correct | 277 ms | 24084 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 11 ms | 1228 KB | Output is correct |
13 | Correct | 257 ms | 24104 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 6 ms | 844 KB | Output is correct |
17 | Correct | 131 ms | 14124 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 0 ms | 204 KB | Output is correct |
20 | Correct | 69 ms | 6260 KB | Output is correct |
21 | Correct | 253 ms | 24068 KB | Output is correct |
22 | Correct | 269 ms | 24272 KB | Output is correct |
23 | Correct | 265 ms | 24060 KB | Output is correct |
24 | Correct | 256 ms | 24104 KB | Output is correct |
25 | Correct | 130 ms | 14128 KB | Output is correct |
26 | Correct | 112 ms | 14196 KB | Output is correct |
27 | Correct | 263 ms | 24060 KB | Output is correct |
28 | Correct | 284 ms | 24132 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 204 KB | Output is correct |
8 | Correct | 11 ms | 1316 KB | Output is correct |
9 | Correct | 275 ms | 24172 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 11 ms | 1316 KB | Output is correct |
13 | Correct | 260 ms | 24056 KB | Output is correct |
14 | Correct | 1 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 304 KB | Output is correct |
16 | Correct | 6 ms | 844 KB | Output is correct |
17 | Correct | 131 ms | 14132 KB | Output is correct |
18 | Correct | 0 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 204 KB | Output is correct |
20 | Correct | 0 ms | 204 KB | Output is correct |
21 | Correct | 64 ms | 6264 KB | Output is correct |
22 | Correct | 259 ms | 24068 KB | Output is correct |
23 | Correct | 258 ms | 24068 KB | Output is correct |
24 | Correct | 267 ms | 24132 KB | Output is correct |
25 | Correct | 117 ms | 14276 KB | Output is correct |
26 | Correct | 116 ms | 14204 KB | Output is correct |
27 | Correct | 262 ms | 24040 KB | Output is correct |
28 | Correct | 279 ms | 24068 KB | Output is correct |
29 | Correct | 116 ms | 14204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 66 ms | 6256 KB | Output is correct |
5 | Correct | 262 ms | 24132 KB | Output is correct |
6 | Correct | 260 ms | 24004 KB | Output is correct |
7 | Correct | 269 ms | 24156 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 66 ms | 6264 KB | Output is correct |
10 | Correct | 253 ms | 24056 KB | Output is correct |
11 | Correct | 263 ms | 24056 KB | Output is correct |
12 | Correct | 268 ms | 24156 KB | Output is correct |
13 | Correct | 1 ms | 204 KB | Output is correct |
14 | Correct | 1 ms | 308 KB | Output is correct |
15 | Correct | 1 ms | 204 KB | Output is correct |
16 | Correct | 73 ms | 6272 KB | Output is correct |
17 | Correct | 253 ms | 24188 KB | Output is correct |
18 | Correct | 260 ms | 24132 KB | Output is correct |
19 | Correct | 266 ms | 24060 KB | Output is correct |
20 | Correct | 251 ms | 24044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 11 ms | 1296 KB | Output is correct |
7 | Correct | 277 ms | 24084 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 11 ms | 1228 KB | Output is correct |
13 | Correct | 257 ms | 24104 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 6 ms | 844 KB | Output is correct |
17 | Correct | 131 ms | 14124 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 0 ms | 204 KB | Output is correct |
20 | Correct | 69 ms | 6260 KB | Output is correct |
21 | Correct | 253 ms | 24068 KB | Output is correct |
22 | Correct | 269 ms | 24272 KB | Output is correct |
23 | Correct | 265 ms | 24060 KB | Output is correct |
24 | Correct | 256 ms | 24104 KB | Output is correct |
25 | Correct | 130 ms | 14128 KB | Output is correct |
26 | Correct | 112 ms | 14196 KB | Output is correct |
27 | Correct | 263 ms | 24060 KB | Output is correct |
28 | Correct | 284 ms | 24132 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 1 ms | 204 KB | Output is correct |
31 | Correct | 1 ms | 204 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
33 | Correct | 1 ms | 204 KB | Output is correct |
34 | Correct | 0 ms | 204 KB | Output is correct |
35 | Correct | 1 ms | 204 KB | Output is correct |
36 | Correct | 11 ms | 1316 KB | Output is correct |
37 | Correct | 275 ms | 24172 KB | Output is correct |
38 | Correct | 1 ms | 204 KB | Output is correct |
39 | Correct | 1 ms | 204 KB | Output is correct |
40 | Correct | 11 ms | 1316 KB | Output is correct |
41 | Correct | 260 ms | 24056 KB | Output is correct |
42 | Correct | 1 ms | 204 KB | Output is correct |
43 | Correct | 0 ms | 304 KB | Output is correct |
44 | Correct | 6 ms | 844 KB | Output is correct |
45 | Correct | 131 ms | 14132 KB | Output is correct |
46 | Correct | 0 ms | 204 KB | Output is correct |
47 | Correct | 1 ms | 204 KB | Output is correct |
48 | Correct | 0 ms | 204 KB | Output is correct |
49 | Correct | 64 ms | 6264 KB | Output is correct |
50 | Correct | 259 ms | 24068 KB | Output is correct |
51 | Correct | 258 ms | 24068 KB | Output is correct |
52 | Correct | 267 ms | 24132 KB | Output is correct |
53 | Correct | 117 ms | 14276 KB | Output is correct |
54 | Correct | 116 ms | 14204 KB | Output is correct |
55 | Correct | 262 ms | 24040 KB | Output is correct |
56 | Correct | 279 ms | 24068 KB | Output is correct |
57 | Correct | 116 ms | 14204 KB | Output is correct |
58 | Correct | 1 ms | 204 KB | Output is correct |
59 | Correct | 1 ms | 308 KB | Output is correct |
60 | Correct | 6 ms | 844 KB | Output is correct |
61 | Correct | 143 ms | 14204 KB | Output is correct |
62 | Correct | 0 ms | 204 KB | Output is correct |
63 | Correct | 1 ms | 204 KB | Output is correct |
64 | Correct | 1 ms | 308 KB | Output is correct |
65 | Correct | 67 ms | 6272 KB | Output is correct |
66 | Correct | 120 ms | 14088 KB | Output is correct |
67 | Correct | 115 ms | 14148 KB | Output is correct |
68 | Correct | 118 ms | 14208 KB | Output is correct |
69 | Correct | 112 ms | 14208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 312 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Correct | 11 ms | 1296 KB | Output is correct |
7 | Correct | 277 ms | 24084 KB | Output is correct |
8 | Correct | 1 ms | 204 KB | Output is correct |
9 | Correct | 0 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 11 ms | 1228 KB | Output is correct |
13 | Correct | 257 ms | 24104 KB | Output is correct |
14 | Correct | 0 ms | 204 KB | Output is correct |
15 | Correct | 0 ms | 204 KB | Output is correct |
16 | Correct | 6 ms | 844 KB | Output is correct |
17 | Correct | 131 ms | 14124 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 0 ms | 204 KB | Output is correct |
20 | Correct | 69 ms | 6260 KB | Output is correct |
21 | Correct | 253 ms | 24068 KB | Output is correct |
22 | Correct | 269 ms | 24272 KB | Output is correct |
23 | Correct | 265 ms | 24060 KB | Output is correct |
24 | Correct | 256 ms | 24104 KB | Output is correct |
25 | Correct | 130 ms | 14128 KB | Output is correct |
26 | Correct | 112 ms | 14196 KB | Output is correct |
27 | Correct | 263 ms | 24060 KB | Output is correct |
28 | Correct | 284 ms | 24132 KB | Output is correct |
29 | Correct | 1 ms | 204 KB | Output is correct |
30 | Correct | 1 ms | 204 KB | Output is correct |
31 | Correct | 1 ms | 204 KB | Output is correct |
32 | Correct | 0 ms | 204 KB | Output is correct |
33 | Correct | 1 ms | 204 KB | Output is correct |
34 | Correct | 0 ms | 204 KB | Output is correct |
35 | Correct | 1 ms | 204 KB | Output is correct |
36 | Correct | 11 ms | 1316 KB | Output is correct |
37 | Correct | 275 ms | 24172 KB | Output is correct |
38 | Correct | 1 ms | 204 KB | Output is correct |
39 | Correct | 1 ms | 204 KB | Output is correct |
40 | Correct | 11 ms | 1316 KB | Output is correct |
41 | Correct | 260 ms | 24056 KB | Output is correct |
42 | Correct | 1 ms | 204 KB | Output is correct |
43 | Correct | 0 ms | 304 KB | Output is correct |
44 | Correct | 6 ms | 844 KB | Output is correct |
45 | Correct | 131 ms | 14132 KB | Output is correct |
46 | Correct | 0 ms | 204 KB | Output is correct |
47 | Correct | 1 ms | 204 KB | Output is correct |
48 | Correct | 0 ms | 204 KB | Output is correct |
49 | Correct | 64 ms | 6264 KB | Output is correct |
50 | Correct | 259 ms | 24068 KB | Output is correct |
51 | Correct | 258 ms | 24068 KB | Output is correct |
52 | Correct | 267 ms | 24132 KB | Output is correct |
53 | Correct | 117 ms | 14276 KB | Output is correct |
54 | Correct | 116 ms | 14204 KB | Output is correct |
55 | Correct | 262 ms | 24040 KB | Output is correct |
56 | Correct | 279 ms | 24068 KB | Output is correct |
57 | Correct | 116 ms | 14204 KB | Output is correct |
58 | Correct | 0 ms | 204 KB | Output is correct |
59 | Correct | 0 ms | 204 KB | Output is correct |
60 | Correct | 1 ms | 204 KB | Output is correct |
61 | Correct | 66 ms | 6256 KB | Output is correct |
62 | Correct | 262 ms | 24132 KB | Output is correct |
63 | Correct | 260 ms | 24004 KB | Output is correct |
64 | Correct | 269 ms | 24156 KB | Output is correct |
65 | Correct | 0 ms | 204 KB | Output is correct |
66 | Correct | 66 ms | 6264 KB | Output is correct |
67 | Correct | 253 ms | 24056 KB | Output is correct |
68 | Correct | 263 ms | 24056 KB | Output is correct |
69 | Correct | 268 ms | 24156 KB | Output is correct |
70 | Correct | 1 ms | 204 KB | Output is correct |
71 | Correct | 1 ms | 308 KB | Output is correct |
72 | Correct | 1 ms | 204 KB | Output is correct |
73 | Correct | 73 ms | 6272 KB | Output is correct |
74 | Correct | 253 ms | 24188 KB | Output is correct |
75 | Correct | 260 ms | 24132 KB | Output is correct |
76 | Correct | 266 ms | 24060 KB | Output is correct |
77 | Correct | 251 ms | 24044 KB | Output is correct |
78 | Correct | 1 ms | 204 KB | Output is correct |
79 | Correct | 1 ms | 308 KB | Output is correct |
80 | Correct | 6 ms | 844 KB | Output is correct |
81 | Correct | 143 ms | 14204 KB | Output is correct |
82 | Correct | 0 ms | 204 KB | Output is correct |
83 | Correct | 1 ms | 204 KB | Output is correct |
84 | Correct | 1 ms | 308 KB | Output is correct |
85 | Correct | 67 ms | 6272 KB | Output is correct |
86 | Correct | 120 ms | 14088 KB | Output is correct |
87 | Correct | 115 ms | 14148 KB | Output is correct |
88 | Correct | 118 ms | 14208 KB | Output is correct |
89 | Correct | 112 ms | 14208 KB | Output is correct |
90 | Correct | 0 ms | 204 KB | Output is correct |
91 | Correct | 1 ms | 304 KB | Output is correct |
92 | Correct | 5 ms | 844 KB | Output is correct |
93 | Correct | 117 ms | 14204 KB | Output is correct |
94 | Correct | 0 ms | 236 KB | Output is correct |
95 | Correct | 1 ms | 204 KB | Output is correct |
96 | Correct | 0 ms | 204 KB | Output is correct |
97 | Correct | 28 ms | 3764 KB | Output is correct |
98 | Correct | 113 ms | 14088 KB | Output is correct |
99 | Correct | 114 ms | 14128 KB | Output is correct |
100 | Correct | 116 ms | 14088 KB | Output is correct |
101 | Correct | 114 ms | 14200 KB | Output is correct |
102 | Correct | 108 ms | 14152 KB | Output is correct |
103 | Correct | 122 ms | 14204 KB | Output is correct |
104 | Correct | 111 ms | 14212 KB | Output is correct |
105 | Correct | 146 ms | 14200 KB | Output is correct |