#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn=1010;
queue<int> q,q2;
bool vis[maxn];
int fa[maxn],line[maxn];
int construct(vector<vector<int> > p) {
int n = p.size();
vector<vector<int> > ans;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
ans.push_back(row);
}
for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (p[i][j]==3) return 0;
int lst;
for (int i=0;i<n;i++) if (!vis[i]) {
q.push(i); vis[i]=1;
vector<int> circle; circle.clear();
while (!q.empty()) {
int u=q.front(); q.pop();
circle.push_back(u);
q2.push(u); lst=-1;
while (!q2.empty()) {
int v=q2.front(); q2.pop();
vis[v]=1;
//printf("%d %d %d\n",i,u,v);
fa[v]=i,line[v]=u;
if (lst>-1) ans[lst][v]=ans[v][lst]=1;
lst=v;
for (int j=0;j<n;j++) if (!vis[j]) {
if (p[v][j]==2) q.push(j),vis[j]=1;
else if (p[v][j]==1) q2.push(j),vis[j]=1;
}
}
}
if (circle.size()<=1) continue;
if (circle.size()==2) return 0;
circle.push_back(circle[0]);
for (int j=0;j<circle.size()-1;j++) ans[circle[j]][circle[j+1]]=ans[circle[j+1]][circle[j]]=1;
}
for (int i=0;i<n;i++)
for (int j=0;j<n;j++) {
if (p[i][j]==0) {
if (fa[i]==fa[j]) return 0;
}
if (p[i][j]==1) {
if (line[i]!=line[j]) return 0;
}
if (p[i][j]==2) {
if (fa[i]!=fa[j]) return 0;
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j=0;j<circle.size()-1;j++) ans[circle[j]][circle[j+1]]=ans[circle[j+1]][circle[j]]=1;
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1152 KB |
Output is correct |
7 |
Correct |
237 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1152 KB |
Output is correct |
7 |
Correct |
237 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1152 KB |
Output is correct |
13 |
Correct |
237 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
108 ms |
12328 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
59 ms |
5880 KB |
Output is correct |
21 |
Correct |
236 ms |
22264 KB |
Output is correct |
22 |
Correct |
234 ms |
22136 KB |
Output is correct |
23 |
Correct |
250 ms |
22140 KB |
Output is correct |
24 |
Correct |
236 ms |
22136 KB |
Output is correct |
25 |
Correct |
103 ms |
12280 KB |
Output is correct |
26 |
Correct |
103 ms |
12152 KB |
Output is correct |
27 |
Correct |
248 ms |
22136 KB |
Output is correct |
28 |
Correct |
237 ms |
22112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 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 |
236 ms |
22136 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 |
1280 KB |
Output is correct |
13 |
Correct |
242 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
109 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
60 ms |
5844 KB |
Output is correct |
22 |
Correct |
244 ms |
22136 KB |
Output is correct |
23 |
Correct |
241 ms |
22124 KB |
Output is correct |
24 |
Correct |
248 ms |
22136 KB |
Output is correct |
25 |
Correct |
102 ms |
12156 KB |
Output is correct |
26 |
Correct |
109 ms |
12152 KB |
Output is correct |
27 |
Correct |
241 ms |
22264 KB |
Output is correct |
28 |
Correct |
243 ms |
22136 KB |
Output is correct |
29 |
Correct |
104 ms |
12152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
72 ms |
5880 KB |
Output is correct |
5 |
Correct |
241 ms |
22136 KB |
Output is correct |
6 |
Correct |
245 ms |
22136 KB |
Output is correct |
7 |
Correct |
246 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
59 ms |
5808 KB |
Output is correct |
10 |
Correct |
243 ms |
22100 KB |
Output is correct |
11 |
Correct |
241 ms |
22108 KB |
Output is correct |
12 |
Correct |
244 ms |
22136 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Incorrect |
34 ms |
3320 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1152 KB |
Output is correct |
7 |
Correct |
237 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1152 KB |
Output is correct |
13 |
Correct |
237 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
108 ms |
12328 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
59 ms |
5880 KB |
Output is correct |
21 |
Correct |
236 ms |
22264 KB |
Output is correct |
22 |
Correct |
234 ms |
22136 KB |
Output is correct |
23 |
Correct |
250 ms |
22140 KB |
Output is correct |
24 |
Correct |
236 ms |
22136 KB |
Output is correct |
25 |
Correct |
103 ms |
12280 KB |
Output is correct |
26 |
Correct |
103 ms |
12152 KB |
Output is correct |
27 |
Correct |
248 ms |
22136 KB |
Output is correct |
28 |
Correct |
237 ms |
22112 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
256 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 |
236 ms |
22136 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 |
1280 KB |
Output is correct |
41 |
Correct |
242 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
109 ms |
12152 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
60 ms |
5844 KB |
Output is correct |
50 |
Correct |
244 ms |
22136 KB |
Output is correct |
51 |
Correct |
241 ms |
22124 KB |
Output is correct |
52 |
Correct |
248 ms |
22136 KB |
Output is correct |
53 |
Correct |
102 ms |
12156 KB |
Output is correct |
54 |
Correct |
109 ms |
12152 KB |
Output is correct |
55 |
Correct |
241 ms |
22264 KB |
Output is correct |
56 |
Correct |
243 ms |
22136 KB |
Output is correct |
57 |
Correct |
104 ms |
12152 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
5 ms |
768 KB |
Output is correct |
61 |
Correct |
111 ms |
12152 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 |
Incorrect |
26 ms |
3328 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1152 KB |
Output is correct |
7 |
Correct |
237 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1152 KB |
Output is correct |
13 |
Correct |
237 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
108 ms |
12328 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
59 ms |
5880 KB |
Output is correct |
21 |
Correct |
236 ms |
22264 KB |
Output is correct |
22 |
Correct |
234 ms |
22136 KB |
Output is correct |
23 |
Correct |
250 ms |
22140 KB |
Output is correct |
24 |
Correct |
236 ms |
22136 KB |
Output is correct |
25 |
Correct |
103 ms |
12280 KB |
Output is correct |
26 |
Correct |
103 ms |
12152 KB |
Output is correct |
27 |
Correct |
248 ms |
22136 KB |
Output is correct |
28 |
Correct |
237 ms |
22112 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
256 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 |
236 ms |
22136 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 |
1280 KB |
Output is correct |
41 |
Correct |
242 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
109 ms |
12152 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
60 ms |
5844 KB |
Output is correct |
50 |
Correct |
244 ms |
22136 KB |
Output is correct |
51 |
Correct |
241 ms |
22124 KB |
Output is correct |
52 |
Correct |
248 ms |
22136 KB |
Output is correct |
53 |
Correct |
102 ms |
12156 KB |
Output is correct |
54 |
Correct |
109 ms |
12152 KB |
Output is correct |
55 |
Correct |
241 ms |
22264 KB |
Output is correct |
56 |
Correct |
243 ms |
22136 KB |
Output is correct |
57 |
Correct |
104 ms |
12152 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 |
256 KB |
Output is correct |
61 |
Correct |
72 ms |
5880 KB |
Output is correct |
62 |
Correct |
241 ms |
22136 KB |
Output is correct |
63 |
Correct |
245 ms |
22136 KB |
Output is correct |
64 |
Correct |
246 ms |
22136 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
59 ms |
5808 KB |
Output is correct |
67 |
Correct |
243 ms |
22100 KB |
Output is correct |
68 |
Correct |
241 ms |
22108 KB |
Output is correct |
69 |
Correct |
244 ms |
22136 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
0 ms |
384 KB |
Output is correct |
73 |
Incorrect |
34 ms |
3320 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |