#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;
const int MAXN = 1e3+10;
int pai[MAXN], peso[MAXN];
int find(int x){ return (pai[x]==x ? x : pai[x]=find(pai[x])); }
void join(int a, int b){
a=find(a);
b=find(b);
if(a==b) return;
if(peso[a]>peso[b]) swap(a, b);
pai[a]=b;
peso[b]=max(peso[a]+1, peso[b]);
}
int root[MAXN];
vector<int> pres[MAXN];
int findRoot(int x){ return (root[x]==x ? x : root[x]=find(root[x])); }
void joinRoot(int a, int b){
a=findRoot(a); b=findRoot(b);
if(a==b) return;
if((int)pres[a].size()>(int)pres[b].size()) swap(a, b);
root[a]=b;
for(auto u : pres[a])
pres[b].pb(u);
}
vector<int> adj[MAXN];
int dobra[MAXN];
vector<vector<int>> mark;
void dfs(int ver, int num, int ini){
mark[ini][ver]=num;
for(auto u : adj[ver]){
if(mark[ini][u]) continue;
if(dobra[ver] && dobra[u]) dfs(u, 2, ini);
else dfs(u, num, ini);
}
}
int construct(vector<vector<int>> p) {
int n = (int)p.size();
vector<vector<int>> ans(n, vector<int>(n, 0));
for(int i=0;i<n;i++) pai[i]=i, peso[i]=0, root[i]=i, pres[i]={i};
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]==1 && find(i)!=find(j)){
join(i, j);
ans[i][j]=ans[j][i]=1;
}
}
}
vector<vector<int>> proc(n);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j]!=2) continue;
int x=find(i), y=find(j);
if(x==y) return 0;
joinRoot(x, y);
}
}
for(int i=0;i<n;i++){
if((int)pres[i].size()<=1) continue;
if((int)pres[i].size()==2) return 0;
for(auto u : pres[i]) dobra[u]=1;
for(int j=1;j<(int)pres[i].size();j++)
ans[pres[i][j-1]][pres[i][j]]=ans[pres[i][j]][pres[i][j-1]]=1;
ans[pres[i].back()][pres[i][0]]=ans[pres[i][0]][pres[i].back()]=1;
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(ans[i][j]) adj[i].pb(j), adj[j].pb(i);
mark.assign(n, vector<int>(n, 0));
for(int i=0;i<n;i++)
dfs(i, 1, i);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(mark[i][j]!=p[i][j]){
return 0;
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1472 KB |
Output is correct |
7 |
Correct |
101 ms |
27484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1472 KB |
Output is correct |
7 |
Correct |
101 ms |
27484 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
98 ms |
27476 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
1240 KB |
Output is correct |
17 |
Correct |
55 ms |
17488 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
25 ms |
7340 KB |
Output is correct |
21 |
Correct |
104 ms |
27552 KB |
Output is correct |
22 |
Correct |
101 ms |
27356 KB |
Output is correct |
23 |
Correct |
114 ms |
27476 KB |
Output is correct |
24 |
Correct |
104 ms |
27516 KB |
Output is correct |
25 |
Correct |
43 ms |
17476 KB |
Output is correct |
26 |
Correct |
51 ms |
17616 KB |
Output is correct |
27 |
Correct |
107 ms |
27732 KB |
Output is correct |
28 |
Correct |
100 ms |
27332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
1624 KB |
Output is correct |
9 |
Correct |
96 ms |
27984 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
105 ms |
28220 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
62 ms |
18188 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
26 ms |
7364 KB |
Output is correct |
22 |
Correct |
102 ms |
28240 KB |
Output is correct |
23 |
Correct |
101 ms |
27988 KB |
Output is correct |
24 |
Correct |
110 ms |
28188 KB |
Output is correct |
25 |
Correct |
40 ms |
14140 KB |
Output is correct |
26 |
Correct |
48 ms |
18256 KB |
Output is correct |
27 |
Correct |
124 ms |
28236 KB |
Output is correct |
28 |
Correct |
109 ms |
28224 KB |
Output is correct |
29 |
Correct |
42 ms |
14144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
25 ms |
7500 KB |
Output is correct |
5 |
Correct |
103 ms |
28196 KB |
Output is correct |
6 |
Correct |
107 ms |
28112 KB |
Output is correct |
7 |
Correct |
113 ms |
28240 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
26 ms |
7256 KB |
Output is correct |
10 |
Correct |
101 ms |
28224 KB |
Output is correct |
11 |
Correct |
110 ms |
27984 KB |
Output is correct |
12 |
Correct |
110 ms |
28096 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
492 KB |
Output is correct |
15 |
Correct |
0 ms |
488 KB |
Output is correct |
16 |
Correct |
25 ms |
7356 KB |
Output is correct |
17 |
Correct |
113 ms |
28180 KB |
Output is correct |
18 |
Correct |
105 ms |
28244 KB |
Output is correct |
19 |
Correct |
101 ms |
28244 KB |
Output is correct |
20 |
Correct |
103 ms |
27964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1472 KB |
Output is correct |
7 |
Correct |
101 ms |
27484 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
98 ms |
27476 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
1240 KB |
Output is correct |
17 |
Correct |
55 ms |
17488 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
25 ms |
7340 KB |
Output is correct |
21 |
Correct |
104 ms |
27552 KB |
Output is correct |
22 |
Correct |
101 ms |
27356 KB |
Output is correct |
23 |
Correct |
114 ms |
27476 KB |
Output is correct |
24 |
Correct |
104 ms |
27516 KB |
Output is correct |
25 |
Correct |
43 ms |
17476 KB |
Output is correct |
26 |
Correct |
51 ms |
17616 KB |
Output is correct |
27 |
Correct |
107 ms |
27732 KB |
Output is correct |
28 |
Correct |
100 ms |
27332 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
1624 KB |
Output is correct |
37 |
Correct |
96 ms |
27984 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
41 |
Correct |
105 ms |
28220 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
62 ms |
18188 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
26 ms |
7364 KB |
Output is correct |
50 |
Correct |
102 ms |
28240 KB |
Output is correct |
51 |
Correct |
101 ms |
27988 KB |
Output is correct |
52 |
Correct |
110 ms |
28188 KB |
Output is correct |
53 |
Correct |
40 ms |
14140 KB |
Output is correct |
54 |
Correct |
48 ms |
18256 KB |
Output is correct |
55 |
Correct |
124 ms |
28236 KB |
Output is correct |
56 |
Correct |
109 ms |
28224 KB |
Output is correct |
57 |
Correct |
42 ms |
14144 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
2 ms |
856 KB |
Output is correct |
61 |
Correct |
46 ms |
14140 KB |
Output is correct |
62 |
Correct |
0 ms |
344 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
26 ms |
7468 KB |
Output is correct |
66 |
Correct |
45 ms |
18364 KB |
Output is correct |
67 |
Correct |
45 ms |
18256 KB |
Output is correct |
68 |
Correct |
42 ms |
18256 KB |
Output is correct |
69 |
Correct |
40 ms |
14140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
1472 KB |
Output is correct |
7 |
Correct |
101 ms |
27484 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
98 ms |
27476 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
1240 KB |
Output is correct |
17 |
Correct |
55 ms |
17488 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
25 ms |
7340 KB |
Output is correct |
21 |
Correct |
104 ms |
27552 KB |
Output is correct |
22 |
Correct |
101 ms |
27356 KB |
Output is correct |
23 |
Correct |
114 ms |
27476 KB |
Output is correct |
24 |
Correct |
104 ms |
27516 KB |
Output is correct |
25 |
Correct |
43 ms |
17476 KB |
Output is correct |
26 |
Correct |
51 ms |
17616 KB |
Output is correct |
27 |
Correct |
107 ms |
27732 KB |
Output is correct |
28 |
Correct |
100 ms |
27332 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
1624 KB |
Output is correct |
37 |
Correct |
96 ms |
27984 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
41 |
Correct |
105 ms |
28220 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
1116 KB |
Output is correct |
45 |
Correct |
62 ms |
18188 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
26 ms |
7364 KB |
Output is correct |
50 |
Correct |
102 ms |
28240 KB |
Output is correct |
51 |
Correct |
101 ms |
27988 KB |
Output is correct |
52 |
Correct |
110 ms |
28188 KB |
Output is correct |
53 |
Correct |
40 ms |
14140 KB |
Output is correct |
54 |
Correct |
48 ms |
18256 KB |
Output is correct |
55 |
Correct |
124 ms |
28236 KB |
Output is correct |
56 |
Correct |
109 ms |
28224 KB |
Output is correct |
57 |
Correct |
42 ms |
14144 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
25 ms |
7500 KB |
Output is correct |
62 |
Correct |
103 ms |
28196 KB |
Output is correct |
63 |
Correct |
107 ms |
28112 KB |
Output is correct |
64 |
Correct |
113 ms |
28240 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
26 ms |
7256 KB |
Output is correct |
67 |
Correct |
101 ms |
28224 KB |
Output is correct |
68 |
Correct |
110 ms |
27984 KB |
Output is correct |
69 |
Correct |
110 ms |
28096 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
492 KB |
Output is correct |
72 |
Correct |
0 ms |
488 KB |
Output is correct |
73 |
Correct |
25 ms |
7356 KB |
Output is correct |
74 |
Correct |
113 ms |
28180 KB |
Output is correct |
75 |
Correct |
105 ms |
28244 KB |
Output is correct |
76 |
Correct |
101 ms |
28244 KB |
Output is correct |
77 |
Correct |
103 ms |
27964 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
2 ms |
856 KB |
Output is correct |
81 |
Correct |
46 ms |
14140 KB |
Output is correct |
82 |
Correct |
0 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
26 ms |
7468 KB |
Output is correct |
86 |
Correct |
45 ms |
18364 KB |
Output is correct |
87 |
Correct |
45 ms |
18256 KB |
Output is correct |
88 |
Correct |
42 ms |
18256 KB |
Output is correct |
89 |
Correct |
40 ms |
14140 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
344 KB |
Output is correct |
92 |
Correct |
2 ms |
992 KB |
Output is correct |
93 |
Correct |
46 ms |
14272 KB |
Output is correct |
94 |
Correct |
0 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
344 KB |
Output is correct |
97 |
Correct |
11 ms |
4956 KB |
Output is correct |
98 |
Correct |
44 ms |
18112 KB |
Output is correct |
99 |
Correct |
47 ms |
18260 KB |
Output is correct |
100 |
Correct |
43 ms |
18256 KB |
Output is correct |
101 |
Correct |
43 ms |
18256 KB |
Output is correct |
102 |
Correct |
41 ms |
18108 KB |
Output is correct |
103 |
Correct |
52 ms |
18260 KB |
Output is correct |
104 |
Correct |
48 ms |
18256 KB |
Output is correct |
105 |
Correct |
51 ms |
18260 KB |
Output is correct |