# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
755095 | 2023-06-09T11:50:58 Z | sofija6 | Connecting Supertrees (IOI20_supertrees) | C++14 | 242 ms | 25088 KB |
#include "supertrees.h" #include <bits/stdc++.h> #define MAXN 1010 using namespace std; int d[MAXN]; int Root(int p) { while (d[p]!=p) { d[p]=d[d[p]]; p=d[p]; } return p; } void Join(int p,int q) { d[Root(p)]=d[Root(q)]; } int construct(std::vector<std::vector<int>> p) { int n=p.size(); for (int i=0;i<n;i++) { d[i]=i; for (int j=0;j<n;j++) { if (p[i][j]==3 || p[i][j]!=p[j][i]) return 0; if (i==j && p[i][j]!=1) return 0; } } vector<int> v[n+2]; for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { if (p[i][j]==1) Join(i,j); } } vector<vector<int> > b; b.resize(n); for (int i=0;i<n;i++) b[i].resize(n); for (int i=0;i<n;i++) { if (i==Root(i)) continue; b[i][Root(i)]=1; b[Root(i)][i]=1; } bool cyc[n+2][n+2]; for (int i=0;i<n;i++) { for (int j=0;j<n;j++) cyc[i][j]=false; } for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { if (p[i][j]==2) cyc[Root(i)][Root(j)]=true; } } vector<int> root[n+2]; for (int i=0;i<n;i++) { root[Root(i)].push_back(i); for (int j=0;j<n;j++) { if (!p[i][j] && (Root(i)==Root(j) || cyc[Root(i)][Root(j)])) return 0; if (p[i][j]==1 && (Root(i)!=Root(j) || cyc[Root(i)][Root(j)])) return 0; if (p[i][j]==2 && (Root(i)==Root(j) || !cyc[Root(i)][Root(j)])) return 0; } } bool vis[n+2]={false}; for (int i=0;i<n;i++) { if (vis[i] || Root(i)!=i) continue; set<int> s; vector<int> v; int cur=i; while (true) { s.insert(cur); v.push_back(cur); vis[cur]=true; bool next=false; for (int j=0;j<n;j++) { if (cyc[cur][j] && !s.count(j)) { cur=j; next=true; break; } } if (!next) break; } if (s.size()==2) return 0; if (s.size()==1) continue; for (int j=0;j<v.size();j++) { for (int k=0;k<v.size();k++) { if (j==k) continue; for (auto U : root[v[j]]) { for (auto V : root[v[k]]) { if (p[U][V]!=2) return 0; } } } } for (int j=0;j<v.size()-1;j++) { b[v[j]][v[j+1]]=1; b[v[j+1]][v[j]]=1; } b[v[v.size()-1]][v[0]]=1; b[v[0]][v[v.size()-1]]=1; } build(b); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1236 KB | Output is correct |
7 | Correct | 189 ms | 23056 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1236 KB | Output is correct |
7 | Correct | 189 ms | 23056 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1236 KB | Output is correct |
13 | Correct | 174 ms | 23056 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 724 KB | Output is correct |
17 | Correct | 86 ms | 13072 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 45 ms | 5964 KB | Output is correct |
21 | Correct | 188 ms | 23056 KB | Output is correct |
22 | Correct | 176 ms | 23060 KB | Output is correct |
23 | Correct | 227 ms | 23040 KB | Output is correct |
24 | Correct | 169 ms | 22988 KB | Output is correct |
25 | Correct | 73 ms | 13132 KB | Output is correct |
26 | Correct | 66 ms | 13072 KB | Output is correct |
27 | Correct | 184 ms | 23140 KB | Output is correct |
28 | Correct | 176 ms | 23048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 9 ms | 1216 KB | Output is correct |
9 | Correct | 186 ms | 22984 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 8 ms | 1236 KB | Output is correct |
13 | Correct | 196 ms | 23096 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 5 ms | 848 KB | Output is correct |
17 | Correct | 116 ms | 13204 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 44 ms | 5996 KB | Output is correct |
22 | Correct | 181 ms | 23116 KB | Output is correct |
23 | Correct | 167 ms | 23044 KB | Output is correct |
24 | Correct | 213 ms | 23060 KB | Output is correct |
25 | Correct | 72 ms | 13192 KB | Output is correct |
26 | Correct | 72 ms | 13192 KB | Output is correct |
27 | Correct | 168 ms | 24968 KB | Output is correct |
28 | Correct | 198 ms | 25088 KB | Output is correct |
29 | Correct | 79 ms | 15096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 46 ms | 5980 KB | Output is correct |
5 | Correct | 195 ms | 22988 KB | Output is correct |
6 | Correct | 171 ms | 22988 KB | Output is correct |
7 | Correct | 205 ms | 23060 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 43 ms | 5976 KB | Output is correct |
10 | Correct | 188 ms | 23060 KB | Output is correct |
11 | Correct | 205 ms | 23080 KB | Output is correct |
12 | Correct | 242 ms | 23116 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 49 ms | 6020 KB | Output is correct |
17 | Correct | 207 ms | 23052 KB | Output is correct |
18 | Correct | 196 ms | 22988 KB | Output is correct |
19 | Correct | 204 ms | 23072 KB | Output is correct |
20 | Correct | 197 ms | 23044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1236 KB | Output is correct |
7 | Correct | 189 ms | 23056 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1236 KB | Output is correct |
13 | Correct | 174 ms | 23056 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 724 KB | Output is correct |
17 | Correct | 86 ms | 13072 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 45 ms | 5964 KB | Output is correct |
21 | Correct | 188 ms | 23056 KB | Output is correct |
22 | Correct | 176 ms | 23060 KB | Output is correct |
23 | Correct | 227 ms | 23040 KB | Output is correct |
24 | Correct | 169 ms | 22988 KB | Output is correct |
25 | Correct | 73 ms | 13132 KB | Output is correct |
26 | Correct | 66 ms | 13072 KB | Output is correct |
27 | Correct | 184 ms | 23140 KB | Output is correct |
28 | Correct | 176 ms | 23048 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 9 ms | 1216 KB | Output is correct |
37 | Correct | 186 ms | 22984 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 8 ms | 1236 KB | Output is correct |
41 | Correct | 196 ms | 23096 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 5 ms | 848 KB | Output is correct |
45 | Correct | 116 ms | 13204 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 0 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 44 ms | 5996 KB | Output is correct |
50 | Correct | 181 ms | 23116 KB | Output is correct |
51 | Correct | 167 ms | 23044 KB | Output is correct |
52 | Correct | 213 ms | 23060 KB | Output is correct |
53 | Correct | 72 ms | 13192 KB | Output is correct |
54 | Correct | 72 ms | 13192 KB | Output is correct |
55 | Correct | 168 ms | 24968 KB | Output is correct |
56 | Correct | 198 ms | 25088 KB | Output is correct |
57 | Correct | 79 ms | 15096 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 1 ms | 212 KB | Output is correct |
60 | Correct | 6 ms | 852 KB | Output is correct |
61 | Correct | 100 ms | 15100 KB | Output is correct |
62 | Correct | 1 ms | 212 KB | Output is correct |
63 | Correct | 1 ms | 212 KB | Output is correct |
64 | Correct | 1 ms | 212 KB | Output is correct |
65 | Correct | 52 ms | 6488 KB | Output is correct |
66 | Correct | 82 ms | 15084 KB | Output is correct |
67 | Correct | 81 ms | 15100 KB | Output is correct |
68 | Correct | 82 ms | 15100 KB | Output is correct |
69 | Correct | 95 ms | 15096 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 8 ms | 1236 KB | Output is correct |
7 | Correct | 189 ms | 23056 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 7 ms | 1236 KB | Output is correct |
13 | Correct | 174 ms | 23056 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 4 ms | 724 KB | Output is correct |
17 | Correct | 86 ms | 13072 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 45 ms | 5964 KB | Output is correct |
21 | Correct | 188 ms | 23056 KB | Output is correct |
22 | Correct | 176 ms | 23060 KB | Output is correct |
23 | Correct | 227 ms | 23040 KB | Output is correct |
24 | Correct | 169 ms | 22988 KB | Output is correct |
25 | Correct | 73 ms | 13132 KB | Output is correct |
26 | Correct | 66 ms | 13072 KB | Output is correct |
27 | Correct | 184 ms | 23140 KB | Output is correct |
28 | Correct | 176 ms | 23048 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 212 KB | Output is correct |
33 | Correct | 1 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 1 ms | 212 KB | Output is correct |
36 | Correct | 9 ms | 1216 KB | Output is correct |
37 | Correct | 186 ms | 22984 KB | Output is correct |
38 | Correct | 1 ms | 212 KB | Output is correct |
39 | Correct | 1 ms | 212 KB | Output is correct |
40 | Correct | 8 ms | 1236 KB | Output is correct |
41 | Correct | 196 ms | 23096 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 1 ms | 212 KB | Output is correct |
44 | Correct | 5 ms | 848 KB | Output is correct |
45 | Correct | 116 ms | 13204 KB | Output is correct |
46 | Correct | 1 ms | 212 KB | Output is correct |
47 | Correct | 0 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 44 ms | 5996 KB | Output is correct |
50 | Correct | 181 ms | 23116 KB | Output is correct |
51 | Correct | 167 ms | 23044 KB | Output is correct |
52 | Correct | 213 ms | 23060 KB | Output is correct |
53 | Correct | 72 ms | 13192 KB | Output is correct |
54 | Correct | 72 ms | 13192 KB | Output is correct |
55 | Correct | 168 ms | 24968 KB | Output is correct |
56 | Correct | 198 ms | 25088 KB | Output is correct |
57 | Correct | 79 ms | 15096 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 1 ms | 212 KB | Output is correct |
60 | Correct | 1 ms | 212 KB | Output is correct |
61 | Correct | 46 ms | 5980 KB | Output is correct |
62 | Correct | 195 ms | 22988 KB | Output is correct |
63 | Correct | 171 ms | 22988 KB | Output is correct |
64 | Correct | 205 ms | 23060 KB | Output is correct |
65 | Correct | 0 ms | 212 KB | Output is correct |
66 | Correct | 43 ms | 5976 KB | Output is correct |
67 | Correct | 188 ms | 23060 KB | Output is correct |
68 | Correct | 205 ms | 23080 KB | Output is correct |
69 | Correct | 242 ms | 23116 KB | Output is correct |
70 | Correct | 1 ms | 212 KB | Output is correct |
71 | Correct | 1 ms | 212 KB | Output is correct |
72 | Correct | 0 ms | 212 KB | Output is correct |
73 | Correct | 49 ms | 6020 KB | Output is correct |
74 | Correct | 207 ms | 23052 KB | Output is correct |
75 | Correct | 196 ms | 22988 KB | Output is correct |
76 | Correct | 204 ms | 23072 KB | Output is correct |
77 | Correct | 197 ms | 23044 KB | Output is correct |
78 | Correct | 1 ms | 212 KB | Output is correct |
79 | Correct | 1 ms | 212 KB | Output is correct |
80 | Correct | 6 ms | 852 KB | Output is correct |
81 | Correct | 100 ms | 15100 KB | Output is correct |
82 | Correct | 1 ms | 212 KB | Output is correct |
83 | Correct | 1 ms | 212 KB | Output is correct |
84 | Correct | 1 ms | 212 KB | Output is correct |
85 | Correct | 52 ms | 6488 KB | Output is correct |
86 | Correct | 82 ms | 15084 KB | Output is correct |
87 | Correct | 81 ms | 15100 KB | Output is correct |
88 | Correct | 82 ms | 15100 KB | Output is correct |
89 | Correct | 95 ms | 15096 KB | Output is correct |
90 | Correct | 1 ms | 212 KB | Output is correct |
91 | Correct | 1 ms | 212 KB | Output is correct |
92 | Correct | 4 ms | 596 KB | Output is correct |
93 | Correct | 91 ms | 10104 KB | Output is correct |
94 | Correct | 1 ms | 212 KB | Output is correct |
95 | Correct | 1 ms | 212 KB | Output is correct |
96 | Correct | 1 ms | 304 KB | Output is correct |
97 | Correct | 19 ms | 2764 KB | Output is correct |
98 | Correct | 97 ms | 10104 KB | Output is correct |
99 | Correct | 70 ms | 10108 KB | Output is correct |
100 | Correct | 114 ms | 10036 KB | Output is correct |
101 | Correct | 70 ms | 10104 KB | Output is correct |
102 | Correct | 81 ms | 10108 KB | Output is correct |
103 | Correct | 67 ms | 10108 KB | Output is correct |
104 | Correct | 70 ms | 10068 KB | Output is correct |
105 | Correct | 78 ms | 10028 KB | Output is correct |