#include <bits/stdc++.h>
using namespace std;
#ifndef ARTHUR_LOCAL
#include "supertrees.h"
#endif
#define len(x) int((x).size())
#ifdef ARTHUR_LOCAL
void build(vector<vector<int>> V)
{
for(auto row:V)
{
for(auto thing:row) cout << thing << " ";
cout << endl;
}
}
#endif
vector<int> comp;
vector<int> adj[1001];
bool vis[1001];
void dfs(int v)
{
vis[v]=1;
comp.push_back(v);
for(auto u:adj[v])
{
if(vis[u]) continue;
dfs(u);
}
}
int construct(vector<vector<int>> P) {
int n = (int)P.size();
vector<vector<int>> answer;
vector<vector<int>> categ;
for (int i = 0; i < n; i++)
{
vector<int> row(n);
answer.push_back(row);
categ.push_back(row);
}
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(P[i][j] == 1)
{
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
vector<int> heads;
vector<vector<int>> headcomps;
vector<int> my_head(n+1);
for(int i=0; i<n; i++)
{
if(vis[i]) continue;
comp.clear();
dfs(i);
int m = (int)comp.size();
heads.push_back(i);
headcomps.push_back(comp);
my_head[i]=i;
for(int k=0; k<m; k++)
{
for(int j=i+1; j<m; j++)
{
if(P[comp[k]][comp[j]] != 1) return 0;
}
}
for(int j=1; j<m; j++)
{
my_head[comp[j]]=i;
answer[comp[0]][comp[j]]=1;
answer[comp[j]][comp[0]]=1;
// answer[comp[i]][comp[(i+1)%m]]=1;
// answer[comp[(i+1)%m]][comp[i]]=1;
}
}
vector<bool> headvis(n+1);
vector<int> head_group(n+1);
// vector<in
for(int i=0; i<len(heads); i++)
{
if(headvis[i]) continue;
headvis[i]=1;
head_group[heads[i]]=heads[i];
vector<int> cur = {heads[i]};
for(int j=i+1; j<len(heads); j++)
{
if(P[heads[i]][heads[j]] == 2)
{
head_group[heads[j]]=heads[i];
cur.push_back(heads[j]);
headvis[j]=1;
}
}
// for(auto c:cur) cout << c << " ";
// cout << endl;
if(len(cur)==1) continue;
if(len(cur)==2) return 0;
for(int j=0; j<len(cur); j++)
{
answer[cur[j]][cur[(j+1)%len(cur)]]=1;
answer[cur[(j+1)%len(cur)]][cur[j]]=1;
}
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(P[i][j] == 0)
{
if(head_group[my_head[i]] == head_group[my_head[j]]) return 0;
}
if(P[i][j] == 2)
{
if(head_group[my_head[i]] != head_group[my_head[j]]) return 0;
}
}
}
build(answer);
return 1;
}
#ifdef ARTHUR_LOCAL
int main()
{
construct({{1,2,2,0},{2,1,2,0},{2,2,1,0},{0,0,0,1}});
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
11 ms |
1664 KB |
Output is correct |
7 |
Correct |
262 ms |
30200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
11 ms |
1664 KB |
Output is correct |
7 |
Correct |
262 ms |
30200 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
10 ms |
1536 KB |
Output is correct |
13 |
Correct |
247 ms |
26232 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1280 KB |
Output is correct |
17 |
Correct |
122 ms |
18936 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
62 ms |
6904 KB |
Output is correct |
21 |
Correct |
243 ms |
26616 KB |
Output is correct |
22 |
Correct |
246 ms |
26224 KB |
Output is correct |
23 |
Correct |
263 ms |
28152 KB |
Output is correct |
24 |
Correct |
244 ms |
26232 KB |
Output is correct |
25 |
Correct |
112 ms |
16632 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
260 ms |
29176 KB |
Output is correct |
28 |
Correct |
247 ms |
26104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
243 ms |
26104 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
263 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
116 ms |
16248 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 |
384 KB |
Output is correct |
21 |
Correct |
63 ms |
6904 KB |
Output is correct |
22 |
Correct |
248 ms |
26104 KB |
Output is correct |
23 |
Correct |
242 ms |
26208 KB |
Output is correct |
24 |
Correct |
254 ms |
26232 KB |
Output is correct |
25 |
Correct |
127 ms |
16248 KB |
Output is correct |
26 |
Correct |
106 ms |
16248 KB |
Output is correct |
27 |
Correct |
243 ms |
26236 KB |
Output is correct |
28 |
Correct |
250 ms |
26108 KB |
Output is correct |
29 |
Correct |
105 ms |
16248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
61 ms |
6904 KB |
Output is correct |
5 |
Correct |
247 ms |
26620 KB |
Output is correct |
6 |
Correct |
243 ms |
26104 KB |
Output is correct |
7 |
Correct |
256 ms |
28156 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
61 ms |
6904 KB |
Output is correct |
10 |
Correct |
254 ms |
26232 KB |
Output is correct |
11 |
Correct |
242 ms |
26232 KB |
Output is correct |
12 |
Correct |
246 ms |
26104 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
61 ms |
7032 KB |
Output is correct |
17 |
Correct |
246 ms |
26108 KB |
Output is correct |
18 |
Correct |
242 ms |
26104 KB |
Output is correct |
19 |
Correct |
242 ms |
26232 KB |
Output is correct |
20 |
Correct |
245 ms |
26092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
11 ms |
1664 KB |
Output is correct |
7 |
Correct |
262 ms |
30200 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
10 ms |
1536 KB |
Output is correct |
13 |
Correct |
247 ms |
26232 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1280 KB |
Output is correct |
17 |
Correct |
122 ms |
18936 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
62 ms |
6904 KB |
Output is correct |
21 |
Correct |
243 ms |
26616 KB |
Output is correct |
22 |
Correct |
246 ms |
26224 KB |
Output is correct |
23 |
Correct |
263 ms |
28152 KB |
Output is correct |
24 |
Correct |
244 ms |
26232 KB |
Output is correct |
25 |
Correct |
112 ms |
16632 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
260 ms |
29176 KB |
Output is correct |
28 |
Correct |
247 ms |
26104 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
243 ms |
26104 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
10 ms |
1408 KB |
Output is correct |
41 |
Correct |
263 ms |
26104 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
116 ms |
16248 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 |
384 KB |
Output is correct |
49 |
Correct |
63 ms |
6904 KB |
Output is correct |
50 |
Correct |
248 ms |
26104 KB |
Output is correct |
51 |
Correct |
242 ms |
26208 KB |
Output is correct |
52 |
Correct |
254 ms |
26232 KB |
Output is correct |
53 |
Correct |
127 ms |
16248 KB |
Output is correct |
54 |
Correct |
106 ms |
16248 KB |
Output is correct |
55 |
Correct |
243 ms |
26236 KB |
Output is correct |
56 |
Correct |
250 ms |
26108 KB |
Output is correct |
57 |
Correct |
105 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
6 ms |
1152 KB |
Output is correct |
61 |
Correct |
117 ms |
18424 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
72 ms |
6904 KB |
Output is correct |
66 |
Correct |
122 ms |
16248 KB |
Output is correct |
67 |
Correct |
114 ms |
16248 KB |
Output is correct |
68 |
Correct |
108 ms |
16272 KB |
Output is correct |
69 |
Correct |
107 ms |
16248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
416 KB |
Output is correct |
6 |
Correct |
11 ms |
1664 KB |
Output is correct |
7 |
Correct |
262 ms |
30200 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
288 KB |
Output is correct |
12 |
Correct |
10 ms |
1536 KB |
Output is correct |
13 |
Correct |
247 ms |
26232 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1280 KB |
Output is correct |
17 |
Correct |
122 ms |
18936 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
62 ms |
6904 KB |
Output is correct |
21 |
Correct |
243 ms |
26616 KB |
Output is correct |
22 |
Correct |
246 ms |
26224 KB |
Output is correct |
23 |
Correct |
263 ms |
28152 KB |
Output is correct |
24 |
Correct |
244 ms |
26232 KB |
Output is correct |
25 |
Correct |
112 ms |
16632 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
260 ms |
29176 KB |
Output is correct |
28 |
Correct |
247 ms |
26104 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
243 ms |
26104 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
10 ms |
1408 KB |
Output is correct |
41 |
Correct |
263 ms |
26104 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
116 ms |
16248 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 |
384 KB |
Output is correct |
49 |
Correct |
63 ms |
6904 KB |
Output is correct |
50 |
Correct |
248 ms |
26104 KB |
Output is correct |
51 |
Correct |
242 ms |
26208 KB |
Output is correct |
52 |
Correct |
254 ms |
26232 KB |
Output is correct |
53 |
Correct |
127 ms |
16248 KB |
Output is correct |
54 |
Correct |
106 ms |
16248 KB |
Output is correct |
55 |
Correct |
243 ms |
26236 KB |
Output is correct |
56 |
Correct |
250 ms |
26108 KB |
Output is correct |
57 |
Correct |
105 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
61 ms |
6904 KB |
Output is correct |
62 |
Correct |
247 ms |
26620 KB |
Output is correct |
63 |
Correct |
243 ms |
26104 KB |
Output is correct |
64 |
Correct |
256 ms |
28156 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
61 ms |
6904 KB |
Output is correct |
67 |
Correct |
254 ms |
26232 KB |
Output is correct |
68 |
Correct |
242 ms |
26232 KB |
Output is correct |
69 |
Correct |
246 ms |
26104 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
512 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
61 ms |
7032 KB |
Output is correct |
74 |
Correct |
246 ms |
26108 KB |
Output is correct |
75 |
Correct |
242 ms |
26104 KB |
Output is correct |
76 |
Correct |
242 ms |
26232 KB |
Output is correct |
77 |
Correct |
245 ms |
26092 KB |
Output is correct |
78 |
Correct |
1 ms |
384 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
6 ms |
1152 KB |
Output is correct |
81 |
Correct |
117 ms |
18424 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
1 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
72 ms |
6904 KB |
Output is correct |
86 |
Correct |
122 ms |
16248 KB |
Output is correct |
87 |
Correct |
114 ms |
16248 KB |
Output is correct |
88 |
Correct |
108 ms |
16272 KB |
Output is correct |
89 |
Correct |
107 ms |
16248 KB |
Output is correct |
90 |
Correct |
1 ms |
384 KB |
Output is correct |
91 |
Correct |
1 ms |
512 KB |
Output is correct |
92 |
Correct |
5 ms |
1024 KB |
Output is correct |
93 |
Correct |
115 ms |
17656 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
96 |
Halted |
0 ms |
0 KB |
- |