#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
int sz(const T &a){return int(a.size());}
const int MAXN=1e3+1;
bool gone[MAXN];
int pathnum[MAXN][MAXN];
int n;
vector<vector<int>> comps;
void dfs(int loc){
comps.back().push_back(loc);
gone[loc]=true;
for(int i=0;i<n;i++){
if(pathnum[loc][i]&&!gone[i]){
dfs(i);
}
}
}
vector<vector<vector<int>>> comps2;
void dfs2(int loc){
comps2.back().back().push_back(loc);
gone[loc]=true;
for(int i=0;i<n;i++){
if(pathnum[loc][i]==1&&!gone[i]){
dfs2(i);
}
}
}
int construct(vector<vector<int>> p){
n=sz(p);
for(int i=0;i<n;i++)for(int j=0;j<n;j++)pathnum[i][j]=p[i][j];
for(int i=0;i<n;i++){
if(!gone[i]){
comps.push_back({});
dfs(i);
}
}
for(auto x:comps){
for(int i=0;i<sz(x);i++)for(int j=i+1;j<sz(x);j++){
if(!pathnum[x[i]][x[j]])return 0;
}
}
fill(gone,gone+n,false);
for(auto x:comps){
comps2.push_back({});
for(auto y:x){
if(!gone[y]){
comps2.back().push_back({});
dfs2(y);
}
}
}
for(auto y:comps2){
for(auto x:y){
for(int i=0;i<sz(x);i++)for(int j=i+1;j<sz(x);j++){
if(pathnum[x[i]][x[j]]!=1)return 0;
}
}
for(int i=0;i<sz(y);i++){
for(int j=i+1;j<sz(y);j++){
for(auto x:y[i]){
for(auto z:y[j]){
if(pathnum[x][z]!=2)return 0;
}
}
}
}
}
vector<vector<int>> adj(n,vector<int>(n,0));
auto addedge=[&](int l, int r){
adj[l][r]=1,adj[r][l]=1;
};
for(auto x:comps2){
if(sz(x)==2)return 0;
for(int i=0;i<sz(x);i++){
if(sz(x)>1)addedge(x[i].back(),x[(i+1)%sz(x)].back());
for(int j=1;j<sz(x[i]);j++){
addedge(x[i][j-1],x[i][j]);
}
}
}
build(adj);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 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 |
12 ms |
2048 KB |
Output is correct |
7 |
Correct |
246 ms |
26120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 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 |
12 ms |
2048 KB |
Output is correct |
7 |
Correct |
246 ms |
26120 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
241 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1408 KB |
Output is correct |
17 |
Correct |
112 ms |
12128 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
62 ms |
7800 KB |
Output is correct |
21 |
Correct |
250 ms |
26104 KB |
Output is correct |
22 |
Correct |
241 ms |
26072 KB |
Output is correct |
23 |
Correct |
252 ms |
25976 KB |
Output is correct |
24 |
Correct |
244 ms |
26232 KB |
Output is correct |
25 |
Correct |
102 ms |
12152 KB |
Output is correct |
26 |
Correct |
100 ms |
12152 KB |
Output is correct |
27 |
Correct |
251 ms |
26104 KB |
Output is correct |
28 |
Correct |
286 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
14 ms |
2048 KB |
Output is correct |
9 |
Correct |
248 ms |
26104 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
248 ms |
26208 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
1408 KB |
Output is correct |
17 |
Correct |
114 ms |
12156 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
62 ms |
7800 KB |
Output is correct |
22 |
Correct |
243 ms |
26104 KB |
Output is correct |
23 |
Correct |
243 ms |
26104 KB |
Output is correct |
24 |
Correct |
250 ms |
26104 KB |
Output is correct |
25 |
Correct |
126 ms |
16248 KB |
Output is correct |
26 |
Correct |
108 ms |
12152 KB |
Output is correct |
27 |
Correct |
240 ms |
26104 KB |
Output is correct |
28 |
Correct |
271 ms |
26104 KB |
Output is correct |
29 |
Correct |
103 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
7800 KB |
Output is correct |
5 |
Correct |
246 ms |
26232 KB |
Output is correct |
6 |
Correct |
240 ms |
26104 KB |
Output is correct |
7 |
Correct |
255 ms |
25976 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
61 ms |
7800 KB |
Output is correct |
10 |
Correct |
244 ms |
26104 KB |
Output is correct |
11 |
Correct |
245 ms |
26104 KB |
Output is correct |
12 |
Correct |
258 ms |
26104 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
61 ms |
7800 KB |
Output is correct |
17 |
Correct |
242 ms |
26104 KB |
Output is correct |
18 |
Correct |
245 ms |
26060 KB |
Output is correct |
19 |
Correct |
243 ms |
26108 KB |
Output is correct |
20 |
Correct |
240 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 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 |
12 ms |
2048 KB |
Output is correct |
7 |
Correct |
246 ms |
26120 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
241 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1408 KB |
Output is correct |
17 |
Correct |
112 ms |
12128 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
62 ms |
7800 KB |
Output is correct |
21 |
Correct |
250 ms |
26104 KB |
Output is correct |
22 |
Correct |
241 ms |
26072 KB |
Output is correct |
23 |
Correct |
252 ms |
25976 KB |
Output is correct |
24 |
Correct |
244 ms |
26232 KB |
Output is correct |
25 |
Correct |
102 ms |
12152 KB |
Output is correct |
26 |
Correct |
100 ms |
12152 KB |
Output is correct |
27 |
Correct |
251 ms |
26104 KB |
Output is correct |
28 |
Correct |
286 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
14 ms |
2048 KB |
Output is correct |
37 |
Correct |
248 ms |
26104 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
2048 KB |
Output is correct |
41 |
Correct |
248 ms |
26208 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
1408 KB |
Output is correct |
45 |
Correct |
114 ms |
12156 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
62 ms |
7800 KB |
Output is correct |
50 |
Correct |
243 ms |
26104 KB |
Output is correct |
51 |
Correct |
243 ms |
26104 KB |
Output is correct |
52 |
Correct |
250 ms |
26104 KB |
Output is correct |
53 |
Correct |
126 ms |
16248 KB |
Output is correct |
54 |
Correct |
108 ms |
12152 KB |
Output is correct |
55 |
Correct |
240 ms |
26104 KB |
Output is correct |
56 |
Correct |
271 ms |
26104 KB |
Output is correct |
57 |
Correct |
103 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 |
5 ms |
1408 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 |
Correct |
61 ms |
7800 KB |
Output is correct |
66 |
Correct |
103 ms |
12152 KB |
Output is correct |
67 |
Correct |
103 ms |
12152 KB |
Output is correct |
68 |
Correct |
104 ms |
12152 KB |
Output is correct |
69 |
Correct |
104 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 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 |
12 ms |
2048 KB |
Output is correct |
7 |
Correct |
246 ms |
26120 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
2048 KB |
Output is correct |
13 |
Correct |
241 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1408 KB |
Output is correct |
17 |
Correct |
112 ms |
12128 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
62 ms |
7800 KB |
Output is correct |
21 |
Correct |
250 ms |
26104 KB |
Output is correct |
22 |
Correct |
241 ms |
26072 KB |
Output is correct |
23 |
Correct |
252 ms |
25976 KB |
Output is correct |
24 |
Correct |
244 ms |
26232 KB |
Output is correct |
25 |
Correct |
102 ms |
12152 KB |
Output is correct |
26 |
Correct |
100 ms |
12152 KB |
Output is correct |
27 |
Correct |
251 ms |
26104 KB |
Output is correct |
28 |
Correct |
286 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
14 ms |
2048 KB |
Output is correct |
37 |
Correct |
248 ms |
26104 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
2048 KB |
Output is correct |
41 |
Correct |
248 ms |
26208 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
1408 KB |
Output is correct |
45 |
Correct |
114 ms |
12156 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
62 ms |
7800 KB |
Output is correct |
50 |
Correct |
243 ms |
26104 KB |
Output is correct |
51 |
Correct |
243 ms |
26104 KB |
Output is correct |
52 |
Correct |
250 ms |
26104 KB |
Output is correct |
53 |
Correct |
126 ms |
16248 KB |
Output is correct |
54 |
Correct |
108 ms |
12152 KB |
Output is correct |
55 |
Correct |
240 ms |
26104 KB |
Output is correct |
56 |
Correct |
271 ms |
26104 KB |
Output is correct |
57 |
Correct |
103 ms |
16248 KB |
Output is correct |
58 |
Correct |
0 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 |
7800 KB |
Output is correct |
62 |
Correct |
246 ms |
26232 KB |
Output is correct |
63 |
Correct |
240 ms |
26104 KB |
Output is correct |
64 |
Correct |
255 ms |
25976 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
61 ms |
7800 KB |
Output is correct |
67 |
Correct |
244 ms |
26104 KB |
Output is correct |
68 |
Correct |
245 ms |
26104 KB |
Output is correct |
69 |
Correct |
258 ms |
26104 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
512 KB |
Output is correct |
73 |
Correct |
61 ms |
7800 KB |
Output is correct |
74 |
Correct |
242 ms |
26104 KB |
Output is correct |
75 |
Correct |
245 ms |
26060 KB |
Output is correct |
76 |
Correct |
243 ms |
26108 KB |
Output is correct |
77 |
Correct |
240 ms |
26104 KB |
Output is correct |
78 |
Correct |
1 ms |
384 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
5 ms |
1408 KB |
Output is correct |
81 |
Correct |
111 ms |
12152 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 |
61 ms |
7800 KB |
Output is correct |
86 |
Correct |
103 ms |
12152 KB |
Output is correct |
87 |
Correct |
103 ms |
12152 KB |
Output is correct |
88 |
Correct |
104 ms |
12152 KB |
Output is correct |
89 |
Correct |
104 ms |
16248 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
1 ms |
384 KB |
Output is correct |
92 |
Correct |
5 ms |
1408 KB |
Output is correct |
93 |
Correct |
111 ms |
12152 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Correct |
0 ms |
384 KB |
Output is correct |
96 |
Correct |
0 ms |
384 KB |
Output is correct |
97 |
Correct |
26 ms |
4216 KB |
Output is correct |
98 |
Correct |
106 ms |
12152 KB |
Output is correct |
99 |
Correct |
104 ms |
12152 KB |
Output is correct |
100 |
Correct |
102 ms |
12152 KB |
Output is correct |
101 |
Correct |
102 ms |
12280 KB |
Output is correct |
102 |
Correct |
107 ms |
12280 KB |
Output is correct |
103 |
Correct |
106 ms |
12248 KB |
Output is correct |
104 |
Correct |
115 ms |
12152 KB |
Output is correct |
105 |
Correct |
118 ms |
12152 KB |
Output is correct |