# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
994867 | 2024-06-08T07:52:55 Z | Newtonabc | Connecting Supertrees (IOI20_supertrees) | C++14 | 197 ms | 24148 KB |
#include "supertrees.h" #include<bits/stdc++.h> using namespace std; const int N=1e3+10; vector<int> v; int pa[N]; bool cy[N][N]; vector<int> adj[N]; int cnt=0; bool vs[N]; void dfs(int u){ vs[u]=true; cnt++; if(adj[u].size()==1) v.push_back(u); for(int i=0;i<adj[u].size();i++){ if(!vs[adj[u][i]]) dfs(adj[u][i]); } } int root(int x){ if(pa[x]==x) return x; else return pa[x]=root(pa[x]); } int construct(vector<vector<int> > p) { int n = p.size(); vector<vector<int> > answer; for (int i = 0; i < n; i++) { vector<int> row(n,0); answer.push_back(row); } for(int i=0;i<n;i++) pa[i]=i; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(p[i][j]==1 && root(i)!=root(j)){ answer[i][j]=1; answer[j][i]=1; pa[root(i)]=root(j); } if(p[i][j]==3) return 0; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(p[i][j]==0){ if(root(i)==root(j)) return 0; } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a,b; if(p[i][j]==2){ a=root(i),b=root(j); if(a==b) continue; pa[a]=b; answer[a][b]=1; answer[b][a]=1; adj[a].push_back(b); adj[b].push_back(a); } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(root(i)==root(j) && p[i][j]==0) return 0; } } for(int i=0;i<n;i++){ cnt=0; if(!vs[i]) dfs(i); if(cnt==2) return 0; if(v.empty()) continue; answer[v[0]][v[1]]=1; answer[v[1]][v[0]]=1; v.clear(); } build(answer); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 10 ms | 1144 KB | Output is correct |
7 | Correct | 124 ms | 22048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 10 ms | 1144 KB | Output is correct |
7 | Correct | 124 ms | 22048 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 7 ms | 1116 KB | Output is correct |
13 | Correct | 125 ms | 22096 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 5 ms | 860 KB | Output is correct |
17 | Correct | 78 ms | 12112 KB | Output is correct |
18 | Correct | 0 ms | 344 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 32 ms | 5896 KB | Output is correct |
21 | Correct | 123 ms | 22096 KB | Output is correct |
22 | Correct | 127 ms | 22096 KB | Output is correct |
23 | Correct | 128 ms | 22056 KB | Output is correct |
24 | Correct | 125 ms | 22096 KB | Output is correct |
25 | Correct | 53 ms | 12116 KB | Output is correct |
26 | Correct | 53 ms | 12116 KB | Output is correct |
27 | Correct | 130 ms | 22100 KB | Output is correct |
28 | Correct | 124 ms | 22068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 5 ms | 1292 KB | Output is correct |
9 | Correct | 164 ms | 22068 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 6 ms | 1372 KB | Output is correct |
13 | Correct | 149 ms | 22128 KB | Output is correct |
14 | Correct | 0 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 472 KB | Output is correct |
16 | Correct | 3 ms | 860 KB | Output is correct |
17 | Correct | 71 ms | 14164 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 344 KB | Output is correct |
21 | Correct | 35 ms | 6228 KB | Output is correct |
22 | Correct | 147 ms | 24148 KB | Output is correct |
23 | Correct | 150 ms | 24144 KB | Output is correct |
24 | Correct | 130 ms | 24144 KB | Output is correct |
25 | Correct | 87 ms | 14164 KB | Output is correct |
26 | Correct | 60 ms | 14248 KB | Output is correct |
27 | Correct | 122 ms | 24144 KB | Output is correct |
28 | Correct | 133 ms | 24148 KB | Output is correct |
29 | Correct | 85 ms | 14032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 46 ms | 5720 KB | Output is correct |
5 | Correct | 120 ms | 22072 KB | Output is correct |
6 | Correct | 197 ms | 22096 KB | Output is correct |
7 | Correct | 127 ms | 22072 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 33 ms | 5776 KB | Output is correct |
10 | Correct | 125 ms | 22016 KB | Output is correct |
11 | Correct | 118 ms | 22100 KB | Output is correct |
12 | Correct | 129 ms | 22044 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 30 ms | 5952 KB | Output is correct |
17 | Correct | 129 ms | 22096 KB | Output is correct |
18 | Correct | 122 ms | 22136 KB | Output is correct |
19 | Correct | 137 ms | 22096 KB | Output is correct |
20 | Correct | 155 ms | 22100 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 10 ms | 1144 KB | Output is correct |
7 | Correct | 124 ms | 22048 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 7 ms | 1116 KB | Output is correct |
13 | Correct | 125 ms | 22096 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 5 ms | 860 KB | Output is correct |
17 | Correct | 78 ms | 12112 KB | Output is correct |
18 | Correct | 0 ms | 344 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 32 ms | 5896 KB | Output is correct |
21 | Correct | 123 ms | 22096 KB | Output is correct |
22 | Correct | 127 ms | 22096 KB | Output is correct |
23 | Correct | 128 ms | 22056 KB | Output is correct |
24 | Correct | 125 ms | 22096 KB | Output is correct |
25 | Correct | 53 ms | 12116 KB | Output is correct |
26 | Correct | 53 ms | 12116 KB | Output is correct |
27 | Correct | 130 ms | 22100 KB | Output is correct |
28 | Correct | 124 ms | 22068 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 0 ms | 348 KB | Output is correct |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 348 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 5 ms | 1292 KB | Output is correct |
37 | Correct | 164 ms | 22068 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 0 ms | 348 KB | Output is correct |
40 | Correct | 6 ms | 1372 KB | Output is correct |
41 | Correct | 149 ms | 22128 KB | Output is correct |
42 | Correct | 0 ms | 344 KB | Output is correct |
43 | Correct | 0 ms | 472 KB | Output is correct |
44 | Correct | 3 ms | 860 KB | Output is correct |
45 | Correct | 71 ms | 14164 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 468 KB | Output is correct |
48 | Correct | 1 ms | 344 KB | Output is correct |
49 | Correct | 35 ms | 6228 KB | Output is correct |
50 | Correct | 147 ms | 24148 KB | Output is correct |
51 | Correct | 150 ms | 24144 KB | Output is correct |
52 | Correct | 130 ms | 24144 KB | Output is correct |
53 | Correct | 87 ms | 14164 KB | Output is correct |
54 | Correct | 60 ms | 14248 KB | Output is correct |
55 | Correct | 122 ms | 24144 KB | Output is correct |
56 | Correct | 133 ms | 24148 KB | Output is correct |
57 | Correct | 85 ms | 14032 KB | Output is correct |
58 | Correct | 1 ms | 344 KB | Output is correct |
59 | Correct | 1 ms | 348 KB | Output is correct |
60 | Correct | 3 ms | 964 KB | Output is correct |
61 | Correct | 63 ms | 14104 KB | Output is correct |
62 | Correct | 1 ms | 348 KB | Output is correct |
63 | Correct | 0 ms | 348 KB | Output is correct |
64 | Correct | 0 ms | 348 KB | Output is correct |
65 | Correct | 57 ms | 6224 KB | Output is correct |
66 | Correct | 66 ms | 14164 KB | Output is correct |
67 | Correct | 51 ms | 14160 KB | Output is correct |
68 | Correct | 52 ms | 14248 KB | Output is correct |
69 | Correct | 96 ms | 14160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 10 ms | 1144 KB | Output is correct |
7 | Correct | 124 ms | 22048 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 7 ms | 1116 KB | Output is correct |
13 | Correct | 125 ms | 22096 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 5 ms | 860 KB | Output is correct |
17 | Correct | 78 ms | 12112 KB | Output is correct |
18 | Correct | 0 ms | 344 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 32 ms | 5896 KB | Output is correct |
21 | Correct | 123 ms | 22096 KB | Output is correct |
22 | Correct | 127 ms | 22096 KB | Output is correct |
23 | Correct | 128 ms | 22056 KB | Output is correct |
24 | Correct | 125 ms | 22096 KB | Output is correct |
25 | Correct | 53 ms | 12116 KB | Output is correct |
26 | Correct | 53 ms | 12116 KB | Output is correct |
27 | Correct | 130 ms | 22100 KB | Output is correct |
28 | Correct | 124 ms | 22068 KB | Output is correct |
29 | Correct | 0 ms | 348 KB | Output is correct |
30 | Correct | 0 ms | 348 KB | Output is correct |
31 | Correct | 0 ms | 348 KB | Output is correct |
32 | Correct | 0 ms | 348 KB | Output is correct |
33 | Correct | 0 ms | 348 KB | Output is correct |
34 | Correct | 1 ms | 348 KB | Output is correct |
35 | Correct | 0 ms | 348 KB | Output is correct |
36 | Correct | 5 ms | 1292 KB | Output is correct |
37 | Correct | 164 ms | 22068 KB | Output is correct |
38 | Correct | 0 ms | 348 KB | Output is correct |
39 | Correct | 0 ms | 348 KB | Output is correct |
40 | Correct | 6 ms | 1372 KB | Output is correct |
41 | Correct | 149 ms | 22128 KB | Output is correct |
42 | Correct | 0 ms | 344 KB | Output is correct |
43 | Correct | 0 ms | 472 KB | Output is correct |
44 | Correct | 3 ms | 860 KB | Output is correct |
45 | Correct | 71 ms | 14164 KB | Output is correct |
46 | Correct | 0 ms | 348 KB | Output is correct |
47 | Correct | 0 ms | 468 KB | Output is correct |
48 | Correct | 1 ms | 344 KB | Output is correct |
49 | Correct | 35 ms | 6228 KB | Output is correct |
50 | Correct | 147 ms | 24148 KB | Output is correct |
51 | Correct | 150 ms | 24144 KB | Output is correct |
52 | Correct | 130 ms | 24144 KB | Output is correct |
53 | Correct | 87 ms | 14164 KB | Output is correct |
54 | Correct | 60 ms | 14248 KB | Output is correct |
55 | Correct | 122 ms | 24144 KB | Output is correct |
56 | Correct | 133 ms | 24148 KB | Output is correct |
57 | Correct | 85 ms | 14032 KB | Output is correct |
58 | Correct | 0 ms | 348 KB | Output is correct |
59 | Correct | 0 ms | 348 KB | Output is correct |
60 | Correct | 1 ms | 348 KB | Output is correct |
61 | Correct | 46 ms | 5720 KB | Output is correct |
62 | Correct | 120 ms | 22072 KB | Output is correct |
63 | Correct | 197 ms | 22096 KB | Output is correct |
64 | Correct | 127 ms | 22072 KB | Output is correct |
65 | Correct | 1 ms | 348 KB | Output is correct |
66 | Correct | 33 ms | 5776 KB | Output is correct |
67 | Correct | 125 ms | 22016 KB | Output is correct |
68 | Correct | 118 ms | 22100 KB | Output is correct |
69 | Correct | 129 ms | 22044 KB | Output is correct |
70 | Correct | 0 ms | 344 KB | Output is correct |
71 | Correct | 0 ms | 348 KB | Output is correct |
72 | Correct | 0 ms | 348 KB | Output is correct |
73 | Correct | 30 ms | 5952 KB | Output is correct |
74 | Correct | 129 ms | 22096 KB | Output is correct |
75 | Correct | 122 ms | 22136 KB | Output is correct |
76 | Correct | 137 ms | 22096 KB | Output is correct |
77 | Correct | 155 ms | 22100 KB | Output is correct |
78 | Correct | 1 ms | 344 KB | Output is correct |
79 | Correct | 1 ms | 348 KB | Output is correct |
80 | Correct | 3 ms | 964 KB | Output is correct |
81 | Correct | 63 ms | 14104 KB | Output is correct |
82 | Correct | 1 ms | 348 KB | Output is correct |
83 | Correct | 0 ms | 348 KB | Output is correct |
84 | Correct | 0 ms | 348 KB | Output is correct |
85 | Correct | 57 ms | 6224 KB | Output is correct |
86 | Correct | 66 ms | 14164 KB | Output is correct |
87 | Correct | 51 ms | 14160 KB | Output is correct |
88 | Correct | 52 ms | 14248 KB | Output is correct |
89 | Correct | 96 ms | 14160 KB | Output is correct |
90 | Correct | 0 ms | 348 KB | Output is correct |
91 | Correct | 1 ms | 344 KB | Output is correct |
92 | Correct | 3 ms | 860 KB | Output is correct |
93 | Correct | 59 ms | 14164 KB | Output is correct |
94 | Correct | 0 ms | 344 KB | Output is correct |
95 | Correct | 0 ms | 348 KB | Output is correct |
96 | Correct | 0 ms | 348 KB | Output is correct |
97 | Correct | 19 ms | 3932 KB | Output is correct |
98 | Correct | 65 ms | 14108 KB | Output is correct |
99 | Correct | 85 ms | 14160 KB | Output is correct |
100 | Correct | 83 ms | 14232 KB | Output is correct |
101 | Correct | 101 ms | 14244 KB | Output is correct |
102 | Correct | 54 ms | 14160 KB | Output is correct |
103 | Correct | 50 ms | 14160 KB | Output is correct |
104 | Correct | 50 ms | 14236 KB | Output is correct |
105 | Correct | 55 ms | 14160 KB | Output is correct |