#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef vector<vector<int> > va;
const int N=1005;
int n,idc[N],idt[N];
bool vis[N];
inline void add(int u,int v,va&g) {g[u][v]=g[v][u]=1;}
int construct(va p){
n=p.size();va g(n,vector<int>(n));
for(int i=0;i<n;i++)
if(find(p[i].begin(),p[i].end(),3)!=p[i].end()) return 0;
for(int i=0;i<n;i++)
if(!vis[i]){
queue<int> qc;qc.push(i);vector<int> c;
while(!qc.empty()){
int u=qc.front();qc.pop();if(vis[u]) continue;
queue<int> qt;qt.push(u);vector<int> t;c.push_back(u);
while(!qt.empty()){
int x=qt.front();qt.pop();if(vis[x]) continue;
t.push_back(x);idt[x]=u;idc[x]=i;vis[x]=1;
for(int j=0;j<n;j++)
if(p[x][j]==1) qt.push(j);
else if(p[x][j]==2) qc.push(j);
}
for(int j=0;j+1<t.size();j++) add(t[j],t[j+1],g);
}
int sz=c.size();if(sz==2) return 0;
if(sz>2) for(int j=0;j<sz;j++) add(c[j],c[(j+1)%sz],g);
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(idt[i]==idt[j]) {if(p[i][j]!=1) return 0;}
else if(idc[i]==idc[j]) {if(p[i][j]!=2) return 0;}
build(g);return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(va)':
supertrees.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int j=0;j+1<t.size();j++) add(t[j],t[j+1],g);
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
256 ms |
24060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
256 ms |
24060 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
251 ms |
24044 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
119 ms |
16108 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
68 ms |
6348 KB |
Output is correct |
21 |
Correct |
255 ms |
24172 KB |
Output is correct |
22 |
Correct |
259 ms |
24172 KB |
Output is correct |
23 |
Correct |
265 ms |
24048 KB |
Output is correct |
24 |
Correct |
254 ms |
24172 KB |
Output is correct |
25 |
Correct |
106 ms |
14316 KB |
Output is correct |
26 |
Correct |
104 ms |
14116 KB |
Output is correct |
27 |
Correct |
264 ms |
24328 KB |
Output is correct |
28 |
Correct |
256 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1260 KB |
Output is correct |
9 |
Correct |
248 ms |
24044 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
257 ms |
24064 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
1004 KB |
Output is correct |
17 |
Correct |
120 ms |
16236 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
64 ms |
6380 KB |
Output is correct |
22 |
Correct |
258 ms |
24148 KB |
Output is correct |
23 |
Correct |
262 ms |
24004 KB |
Output is correct |
24 |
Correct |
264 ms |
24152 KB |
Output is correct |
25 |
Correct |
103 ms |
14188 KB |
Output is correct |
26 |
Correct |
105 ms |
14188 KB |
Output is correct |
27 |
Correct |
251 ms |
24044 KB |
Output is correct |
28 |
Correct |
264 ms |
24060 KB |
Output is correct |
29 |
Correct |
104 ms |
14188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
65 ms |
6380 KB |
Output is correct |
5 |
Correct |
251 ms |
24044 KB |
Output is correct |
6 |
Correct |
254 ms |
24044 KB |
Output is correct |
7 |
Correct |
260 ms |
24068 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
64 ms |
6380 KB |
Output is correct |
10 |
Correct |
255 ms |
24172 KB |
Output is correct |
11 |
Correct |
253 ms |
24044 KB |
Output is correct |
12 |
Correct |
263 ms |
24152 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
63 ms |
6380 KB |
Output is correct |
17 |
Correct |
271 ms |
24044 KB |
Output is correct |
18 |
Correct |
256 ms |
24196 KB |
Output is correct |
19 |
Correct |
252 ms |
24044 KB |
Output is correct |
20 |
Correct |
250 ms |
24300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
256 ms |
24060 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
251 ms |
24044 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
119 ms |
16108 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
68 ms |
6348 KB |
Output is correct |
21 |
Correct |
255 ms |
24172 KB |
Output is correct |
22 |
Correct |
259 ms |
24172 KB |
Output is correct |
23 |
Correct |
265 ms |
24048 KB |
Output is correct |
24 |
Correct |
254 ms |
24172 KB |
Output is correct |
25 |
Correct |
106 ms |
14316 KB |
Output is correct |
26 |
Correct |
104 ms |
14116 KB |
Output is correct |
27 |
Correct |
264 ms |
24328 KB |
Output is correct |
28 |
Correct |
256 ms |
24044 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
248 ms |
24044 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1260 KB |
Output is correct |
41 |
Correct |
257 ms |
24064 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
1004 KB |
Output is correct |
45 |
Correct |
120 ms |
16236 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
376 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
6380 KB |
Output is correct |
50 |
Correct |
258 ms |
24148 KB |
Output is correct |
51 |
Correct |
262 ms |
24004 KB |
Output is correct |
52 |
Correct |
264 ms |
24152 KB |
Output is correct |
53 |
Correct |
103 ms |
14188 KB |
Output is correct |
54 |
Correct |
105 ms |
14188 KB |
Output is correct |
55 |
Correct |
251 ms |
24044 KB |
Output is correct |
56 |
Correct |
264 ms |
24060 KB |
Output is correct |
57 |
Correct |
104 ms |
14188 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
5 ms |
1004 KB |
Output is correct |
61 |
Correct |
122 ms |
16876 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
63 ms |
6380 KB |
Output is correct |
66 |
Correct |
107 ms |
14276 KB |
Output is correct |
67 |
Correct |
112 ms |
14188 KB |
Output is correct |
68 |
Correct |
104 ms |
14188 KB |
Output is correct |
69 |
Correct |
100 ms |
14188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
256 ms |
24060 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
251 ms |
24044 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1004 KB |
Output is correct |
17 |
Correct |
119 ms |
16108 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
68 ms |
6348 KB |
Output is correct |
21 |
Correct |
255 ms |
24172 KB |
Output is correct |
22 |
Correct |
259 ms |
24172 KB |
Output is correct |
23 |
Correct |
265 ms |
24048 KB |
Output is correct |
24 |
Correct |
254 ms |
24172 KB |
Output is correct |
25 |
Correct |
106 ms |
14316 KB |
Output is correct |
26 |
Correct |
104 ms |
14116 KB |
Output is correct |
27 |
Correct |
264 ms |
24328 KB |
Output is correct |
28 |
Correct |
256 ms |
24044 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
248 ms |
24044 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1260 KB |
Output is correct |
41 |
Correct |
257 ms |
24064 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
1004 KB |
Output is correct |
45 |
Correct |
120 ms |
16236 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
376 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
64 ms |
6380 KB |
Output is correct |
50 |
Correct |
258 ms |
24148 KB |
Output is correct |
51 |
Correct |
262 ms |
24004 KB |
Output is correct |
52 |
Correct |
264 ms |
24152 KB |
Output is correct |
53 |
Correct |
103 ms |
14188 KB |
Output is correct |
54 |
Correct |
105 ms |
14188 KB |
Output is correct |
55 |
Correct |
251 ms |
24044 KB |
Output is correct |
56 |
Correct |
264 ms |
24060 KB |
Output is correct |
57 |
Correct |
104 ms |
14188 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
65 ms |
6380 KB |
Output is correct |
62 |
Correct |
251 ms |
24044 KB |
Output is correct |
63 |
Correct |
254 ms |
24044 KB |
Output is correct |
64 |
Correct |
260 ms |
24068 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
64 ms |
6380 KB |
Output is correct |
67 |
Correct |
255 ms |
24172 KB |
Output is correct |
68 |
Correct |
253 ms |
24044 KB |
Output is correct |
69 |
Correct |
263 ms |
24152 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
63 ms |
6380 KB |
Output is correct |
74 |
Correct |
271 ms |
24044 KB |
Output is correct |
75 |
Correct |
256 ms |
24196 KB |
Output is correct |
76 |
Correct |
252 ms |
24044 KB |
Output is correct |
77 |
Correct |
250 ms |
24300 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
5 ms |
1004 KB |
Output is correct |
81 |
Correct |
122 ms |
16876 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
63 ms |
6380 KB |
Output is correct |
86 |
Correct |
107 ms |
14276 KB |
Output is correct |
87 |
Correct |
112 ms |
14188 KB |
Output is correct |
88 |
Correct |
104 ms |
14188 KB |
Output is correct |
89 |
Correct |
100 ms |
14188 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
876 KB |
Output is correct |
93 |
Correct |
104 ms |
14060 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
26 ms |
3820 KB |
Output is correct |
98 |
Correct |
101 ms |
14060 KB |
Output is correct |
99 |
Correct |
104 ms |
14060 KB |
Output is correct |
100 |
Correct |
100 ms |
14060 KB |
Output is correct |
101 |
Correct |
100 ms |
14060 KB |
Output is correct |
102 |
Correct |
102 ms |
14060 KB |
Output is correct |
103 |
Correct |
106 ms |
14060 KB |
Output is correct |
104 |
Correct |
101 ms |
14060 KB |
Output is correct |
105 |
Correct |
119 ms |
14164 KB |
Output is correct |