#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
const int N = 1005;
int par[N];
int siz[N];
int find(int a)
{
if(par[a]==a) return a;
return par[a]=find(par[a]);
}
void unite(int a,int b)
{
a=find(a),b=find(b);
if(a==b) return;
if(siz[a]>siz[b]) swap(a,b);
siz[b]+=siz[a];
par[a]=b;
}
int construct(vector<vector<int>> p) {
iota(par,par+N,0LL);
fill(siz,siz+N,1LL);
int n = p[0].size();
vector<vector<int>> g(n,vector<int>(n,0));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(p[i][j]) unite(i,j);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(!p[i][j] && find(i)==find(j))
return 0;
vector<int> no[n];
for(int i=0;i<n;i++) no[find(i)].pb(i);
for(int xd=0;xd<n;xd++)
{
if(no[xd].size()<=1) continue;
int m = no[xd].size();
vector<vector<int>> v[m];
set<int> s;
vector<int> deg(m,0);
for(int i=0;i<m;i++)
{
for(int j=i+1;j<m;j++)
{
if(i==j) continue;
if(p[i][j]==2)
{
s.insert(i);
s.insert(j);
deg[i]++;
deg[j]++;
}
}
}
int k=s.size();
if(k==2) return 0;
for(int x:s) if(deg[x]!=k-1) return 0;
if(k>0)
{
int a=*s.begin();
int b=*s.rbegin();
g[a][b]=g[b][a]=1;
}
for(int i=1;i<m;i++)
g[no[xd][i]][no[xd][i-1]]=g[no[xd][i-1]][no[xd][i]]=1;
}
build(g);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
158 ms |
22144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
158 ms |
22144 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
161 ms |
22152 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
75 ms |
12236 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
5800 KB |
Output is correct |
21 |
Correct |
159 ms |
22208 KB |
Output is correct |
22 |
Correct |
160 ms |
22092 KB |
Output is correct |
23 |
Correct |
166 ms |
22204 KB |
Output is correct |
24 |
Correct |
160 ms |
22144 KB |
Output is correct |
25 |
Correct |
66 ms |
12236 KB |
Output is correct |
26 |
Correct |
65 ms |
12256 KB |
Output is correct |
27 |
Correct |
165 ms |
22204 KB |
Output is correct |
28 |
Correct |
160 ms |
22196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
155 ms |
22224 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
184 ms |
22140 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
804 KB |
Output is correct |
17 |
Correct |
77 ms |
12324 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
18 ms |
3412 KB |
Answer gives possible 0 while actual possible 1 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
42 ms |
5800 KB |
Output is correct |
5 |
Correct |
161 ms |
22128 KB |
Output is correct |
6 |
Correct |
158 ms |
22168 KB |
Output is correct |
7 |
Correct |
187 ms |
22220 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
17 ms |
3404 KB |
Answer gives possible 0 while actual possible 1 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
158 ms |
22144 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
161 ms |
22152 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
75 ms |
12236 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
5800 KB |
Output is correct |
21 |
Correct |
159 ms |
22208 KB |
Output is correct |
22 |
Correct |
160 ms |
22092 KB |
Output is correct |
23 |
Correct |
166 ms |
22204 KB |
Output is correct |
24 |
Correct |
160 ms |
22144 KB |
Output is correct |
25 |
Correct |
66 ms |
12236 KB |
Output is correct |
26 |
Correct |
65 ms |
12256 KB |
Output is correct |
27 |
Correct |
165 ms |
22204 KB |
Output is correct |
28 |
Correct |
160 ms |
22196 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
155 ms |
22224 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1236 KB |
Output is correct |
41 |
Correct |
184 ms |
22140 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
804 KB |
Output is correct |
45 |
Correct |
77 ms |
12324 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Incorrect |
18 ms |
3412 KB |
Answer gives possible 0 while actual possible 1 |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
158 ms |
22144 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
161 ms |
22152 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
75 ms |
12236 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
40 ms |
5800 KB |
Output is correct |
21 |
Correct |
159 ms |
22208 KB |
Output is correct |
22 |
Correct |
160 ms |
22092 KB |
Output is correct |
23 |
Correct |
166 ms |
22204 KB |
Output is correct |
24 |
Correct |
160 ms |
22144 KB |
Output is correct |
25 |
Correct |
66 ms |
12236 KB |
Output is correct |
26 |
Correct |
65 ms |
12256 KB |
Output is correct |
27 |
Correct |
165 ms |
22204 KB |
Output is correct |
28 |
Correct |
160 ms |
22196 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
155 ms |
22224 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1236 KB |
Output is correct |
41 |
Correct |
184 ms |
22140 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
804 KB |
Output is correct |
45 |
Correct |
77 ms |
12324 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Incorrect |
18 ms |
3412 KB |
Answer gives possible 0 while actual possible 1 |
50 |
Halted |
0 ms |
0 KB |
- |