#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1005;
int par[NMAX], vis[NMAX], p[NMAX][NMAX], a, b;
vector<int> C[NMAX], V, t;
int find(int x){return par[x] == -1 ? x : par[x] = find(par[x]);}
void dfs(int x){
if(vis[x]) return;
vis[x] = 1;
t.emplace_back(x);
for(int& y : V) if(!vis[y] && p[x][y] == 2) dfs(y);
return;
}
int construct(vector<vector<int>>p_){
int n = p_.size(), a, b;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) p[i][j] = p_[i][j];
vector<vector<int>> E(n, vector<int>(n, 0));
memset(par, -1, sizeof(par));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
if(p[i][j] == 3) return 0;
a = find(i); b = find(j);
if(a == b) continue;
if(p[i][j] == 1){
par[b] = a; E[i][j] = E[j][i] = 1;
}
}
for(int i = 0; i < n; i++) C[find(i)].emplace_back(i);
for(int i = 0; i < n; i++)
if(find(i) == i){
V.emplace_back(i);
for(int&x : C[i])
for(int j = 0; j < n; j++)
if(p[x][j] != p[i][j]) return 0;
}
for(int& x : V)
if(!vis[x]){
t.clear();
dfs(x);
int sz = t.size();
if(sz == 1) continue;
for(int i = 0; i < sz; i++){
a = t[i], b = t[(i + 1) % sz];
E[a][b] = E[b][a] = 1;
for(int j = 0; j < sz; j++)
if(i != j && p[t[i]][t[j]] != 2) return 0;
}
}
build(E);
return 1;
}
/*
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<vector<int>> v (n, vector<int>(n, 0));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) cin >> v[i][j];
cout << construct(v) << '\n';
return 0;
}
*/
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
2
1 0
0 1
2
1 3
3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1984 KB |
Output is correct |
7 |
Correct |
192 ms |
27924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1984 KB |
Output is correct |
7 |
Correct |
192 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
2004 KB |
Output is correct |
13 |
Correct |
194 ms |
27904 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1620 KB |
Output is correct |
17 |
Correct |
79 ms |
18008 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
8156 KB |
Output is correct |
21 |
Correct |
162 ms |
27920 KB |
Output is correct |
22 |
Correct |
178 ms |
27940 KB |
Output is correct |
23 |
Correct |
167 ms |
27980 KB |
Output is correct |
24 |
Correct |
170 ms |
27932 KB |
Output is correct |
25 |
Correct |
71 ms |
17948 KB |
Output is correct |
26 |
Correct |
71 ms |
18076 KB |
Output is correct |
27 |
Correct |
164 ms |
27932 KB |
Output is correct |
28 |
Correct |
160 ms |
27980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
41 ms |
8220 KB |
Output is correct |
5 |
Correct |
174 ms |
27920 KB |
Output is correct |
6 |
Correct |
180 ms |
27864 KB |
Output is correct |
7 |
Correct |
164 ms |
27932 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
40 ms |
8264 KB |
Output is correct |
10 |
Correct |
179 ms |
27952 KB |
Output is correct |
11 |
Correct |
162 ms |
28008 KB |
Output is correct |
12 |
Correct |
166 ms |
27924 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
43 ms |
8200 KB |
Output is correct |
17 |
Correct |
174 ms |
27936 KB |
Output is correct |
18 |
Correct |
164 ms |
27972 KB |
Output is correct |
19 |
Correct |
163 ms |
27932 KB |
Output is correct |
20 |
Correct |
163 ms |
27992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1984 KB |
Output is correct |
7 |
Correct |
192 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
2004 KB |
Output is correct |
13 |
Correct |
194 ms |
27904 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1620 KB |
Output is correct |
17 |
Correct |
79 ms |
18008 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
8156 KB |
Output is correct |
21 |
Correct |
162 ms |
27920 KB |
Output is correct |
22 |
Correct |
178 ms |
27940 KB |
Output is correct |
23 |
Correct |
167 ms |
27980 KB |
Output is correct |
24 |
Correct |
170 ms |
27932 KB |
Output is correct |
25 |
Correct |
71 ms |
17948 KB |
Output is correct |
26 |
Correct |
71 ms |
18076 KB |
Output is correct |
27 |
Correct |
164 ms |
27932 KB |
Output is correct |
28 |
Correct |
160 ms |
27980 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
1984 KB |
Output is correct |
7 |
Correct |
192 ms |
27924 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
2004 KB |
Output is correct |
13 |
Correct |
194 ms |
27904 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1620 KB |
Output is correct |
17 |
Correct |
79 ms |
18008 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
8156 KB |
Output is correct |
21 |
Correct |
162 ms |
27920 KB |
Output is correct |
22 |
Correct |
178 ms |
27940 KB |
Output is correct |
23 |
Correct |
167 ms |
27980 KB |
Output is correct |
24 |
Correct |
170 ms |
27932 KB |
Output is correct |
25 |
Correct |
71 ms |
17948 KB |
Output is correct |
26 |
Correct |
71 ms |
18076 KB |
Output is correct |
27 |
Correct |
164 ms |
27932 KB |
Output is correct |
28 |
Correct |
160 ms |
27980 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |