#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
int root[1020] , de[1020] , use[1020] , r[1020];
ll find(int u){
if(root[u] == u) return u;
return root[u] = find(root[u]);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n , vector<int>(n , 0));
for(int i = 0 ; i < n ; ++i){
if(p[i][i] != 1) return 0 ;
root[i] = i ;
}
for(int i = 0 ; i < n; ++i)
for(int j = 0 ; j < n; ++j){
if(p[i][j] == 2 || p[i][j] == 0) r[i]++ ;
if(!p[i][j]) continue ;
root[find(i)] = find(j);
}
for(int i = 0 ; i < n ; ++i) {
if(r[i] == n - 1) de[i] = 1;
else de[i] = 0 ;
find(i);
}
set<int> s[1020][3];
for(int i = 0 ; i < n; ++i)
for(int j = i + 1 ; j < n; ++j){
if(p[i][j] == 0 && root[i] == root[j]) return 0 ;
else if(p[i][j]){
s[root[i]][de[i]].insert(i);
s[root[i]][de[j]].insert(j);
}
}
for(int i = 0 ; i < n; ++i){
if(use[root[i]]) continue;
use[root[i]] = 1;
int ls = -1;
if(!s[root[i]][1].size()){
for(auto j : s[root[i]][0]){
if(ls != -1){
answer[ls][j] = 1;answer[j][ls] = 1;
}else ls = j ;
}
}else if(!s[root[i]][0].size()){
if(s[root[i]][1].size() <= 2) return 0;
auto it = s[root[i]][1].begin();
auto it1 = s[root[i]][1].begin(); it1++;
auto it2 = s[root[i]][1].begin(); it2++;it2++;
answer[*it][*it1] = 1;answer[*it1][*it] = 1;
for(; it2 != s[root[i]][1].end(); it2++ , it1++){
answer[*it2][*it1] = 1;answer[*it1][*it2] = 1;
}
answer[*it][*it1] = 1;answer[*it1][*it] = 1;
}else{
if(s[root[i]][1].size() <= 1) return 0;
for(auto j : s[root[i]][0]){
if(ls != -1){
answer[ls][j] = 1;answer[j][ls] = 1;
}else ls = j ;
}
int it = ls;
auto it1 = s[root[i]][1].begin();
auto it2 = s[root[i]][1].begin(); it2++;
answer[it][*it1] = 1;answer[*it1][it] = 1;
for(; it2 != s[root[i]][1].end(); it2++ , it1++){
answer[*it2][*it1] = 1;answer[*it1][*it2] = 1;
}
answer[it][*it1] = 1;answer[*it1][it] = 1;
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
17 ms |
1408 KB |
Output is correct |
7 |
Correct |
295 ms |
22360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
17 ms |
1408 KB |
Output is correct |
7 |
Correct |
295 ms |
22360 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
258 ms |
22264 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
124 ms |
12408 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
61 ms |
6008 KB |
Output is correct |
21 |
Correct |
249 ms |
22264 KB |
Output is correct |
22 |
Correct |
242 ms |
22360 KB |
Output is correct |
23 |
Correct |
276 ms |
22264 KB |
Output is correct |
24 |
Correct |
234 ms |
22264 KB |
Output is correct |
25 |
Correct |
106 ms |
12508 KB |
Output is correct |
26 |
Correct |
104 ms |
12280 KB |
Output is correct |
27 |
Correct |
276 ms |
22264 KB |
Output is correct |
28 |
Correct |
237 ms |
22264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
243 ms |
22264 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
1408 KB |
Output is correct |
13 |
Correct |
299 ms |
22392 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
123 ms |
12408 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
60 ms |
6008 KB |
Output is correct |
22 |
Correct |
254 ms |
22268 KB |
Output is correct |
23 |
Correct |
251 ms |
22392 KB |
Output is correct |
24 |
Correct |
276 ms |
22392 KB |
Output is correct |
25 |
Correct |
104 ms |
12280 KB |
Output is correct |
26 |
Correct |
108 ms |
12280 KB |
Output is correct |
27 |
Correct |
246 ms |
22276 KB |
Output is correct |
28 |
Correct |
281 ms |
22264 KB |
Output is correct |
29 |
Correct |
109 ms |
12284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
62 ms |
6040 KB |
Output is correct |
5 |
Correct |
252 ms |
22264 KB |
Output is correct |
6 |
Correct |
246 ms |
22264 KB |
Output is correct |
7 |
Correct |
283 ms |
22264 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
61 ms |
6008 KB |
Output is correct |
10 |
Correct |
247 ms |
22364 KB |
Output is correct |
11 |
Correct |
243 ms |
22264 KB |
Output is correct |
12 |
Correct |
276 ms |
22300 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Incorrect |
27 ms |
3448 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
17 ms |
1408 KB |
Output is correct |
7 |
Correct |
295 ms |
22360 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
258 ms |
22264 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
124 ms |
12408 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
61 ms |
6008 KB |
Output is correct |
21 |
Correct |
249 ms |
22264 KB |
Output is correct |
22 |
Correct |
242 ms |
22360 KB |
Output is correct |
23 |
Correct |
276 ms |
22264 KB |
Output is correct |
24 |
Correct |
234 ms |
22264 KB |
Output is correct |
25 |
Correct |
106 ms |
12508 KB |
Output is correct |
26 |
Correct |
104 ms |
12280 KB |
Output is correct |
27 |
Correct |
276 ms |
22264 KB |
Output is correct |
28 |
Correct |
237 ms |
22264 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
243 ms |
22264 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
12 ms |
1408 KB |
Output is correct |
41 |
Correct |
299 ms |
22392 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
896 KB |
Output is correct |
45 |
Correct |
123 ms |
12408 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
60 ms |
6008 KB |
Output is correct |
50 |
Correct |
254 ms |
22268 KB |
Output is correct |
51 |
Correct |
251 ms |
22392 KB |
Output is correct |
52 |
Correct |
276 ms |
22392 KB |
Output is correct |
53 |
Correct |
104 ms |
12280 KB |
Output is correct |
54 |
Correct |
108 ms |
12280 KB |
Output is correct |
55 |
Correct |
246 ms |
22276 KB |
Output is correct |
56 |
Correct |
281 ms |
22264 KB |
Output is correct |
57 |
Correct |
109 ms |
12284 KB |
Output is correct |
58 |
Correct |
1 ms |
512 KB |
Output is correct |
59 |
Correct |
1 ms |
512 KB |
Output is correct |
60 |
Correct |
6 ms |
896 KB |
Output is correct |
61 |
Correct |
128 ms |
12280 KB |
Output is correct |
62 |
Correct |
1 ms |
512 KB |
Output is correct |
63 |
Correct |
1 ms |
512 KB |
Output is correct |
64 |
Correct |
1 ms |
512 KB |
Output is correct |
65 |
Incorrect |
27 ms |
3456 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
17 ms |
1408 KB |
Output is correct |
7 |
Correct |
295 ms |
22360 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
258 ms |
22264 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
124 ms |
12408 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
61 ms |
6008 KB |
Output is correct |
21 |
Correct |
249 ms |
22264 KB |
Output is correct |
22 |
Correct |
242 ms |
22360 KB |
Output is correct |
23 |
Correct |
276 ms |
22264 KB |
Output is correct |
24 |
Correct |
234 ms |
22264 KB |
Output is correct |
25 |
Correct |
106 ms |
12508 KB |
Output is correct |
26 |
Correct |
104 ms |
12280 KB |
Output is correct |
27 |
Correct |
276 ms |
22264 KB |
Output is correct |
28 |
Correct |
237 ms |
22264 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
243 ms |
22264 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
12 ms |
1408 KB |
Output is correct |
41 |
Correct |
299 ms |
22392 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
896 KB |
Output is correct |
45 |
Correct |
123 ms |
12408 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
60 ms |
6008 KB |
Output is correct |
50 |
Correct |
254 ms |
22268 KB |
Output is correct |
51 |
Correct |
251 ms |
22392 KB |
Output is correct |
52 |
Correct |
276 ms |
22392 KB |
Output is correct |
53 |
Correct |
104 ms |
12280 KB |
Output is correct |
54 |
Correct |
108 ms |
12280 KB |
Output is correct |
55 |
Correct |
246 ms |
22276 KB |
Output is correct |
56 |
Correct |
281 ms |
22264 KB |
Output is correct |
57 |
Correct |
109 ms |
12284 KB |
Output is correct |
58 |
Correct |
1 ms |
512 KB |
Output is correct |
59 |
Correct |
1 ms |
512 KB |
Output is correct |
60 |
Correct |
1 ms |
512 KB |
Output is correct |
61 |
Correct |
62 ms |
6040 KB |
Output is correct |
62 |
Correct |
252 ms |
22264 KB |
Output is correct |
63 |
Correct |
246 ms |
22264 KB |
Output is correct |
64 |
Correct |
283 ms |
22264 KB |
Output is correct |
65 |
Correct |
1 ms |
512 KB |
Output is correct |
66 |
Correct |
61 ms |
6008 KB |
Output is correct |
67 |
Correct |
247 ms |
22364 KB |
Output is correct |
68 |
Correct |
243 ms |
22264 KB |
Output is correct |
69 |
Correct |
276 ms |
22300 KB |
Output is correct |
70 |
Correct |
1 ms |
512 KB |
Output is correct |
71 |
Correct |
1 ms |
512 KB |
Output is correct |
72 |
Correct |
1 ms |
512 KB |
Output is correct |
73 |
Incorrect |
27 ms |
3448 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |