#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int n,l[1001];
vector <int> v,ve[1001];
vector <vector <int>> g;
int f(int u){
return (l[u]<0?u:l[u]=f(l[u]));
}
bool unite(int u, int v){
u=f(u);
v=f(v);
if (u==v)
return false;
if (l[u]<l[v])
swap(u,v);
l[u]+=l[v];
l[v]=u;
return true;
}
int construct(vector <vector <int>> p){
n=p.size();
g.resize(n);
for (int i=0;i<n;i++)
g[i].resize(n);
memset(l,-1,sizeof(l));
for (auto i:p)
for (int j:i)
if (j==3)
return 0;
for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++)
if (p[i][j]==1)
g[i][j]=g[j][i]=unite(i,j);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (f(i)==f(j)&&p[i][j]!=1)
return 0;
for (int i=0;i<n;i++)
if (f(i)==i)
v.push_back(i);
memset(l,-1,sizeof(l));
for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++)
if (p[i][j]==2)
unite(i,j);
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (f(i)==f(j)&&!p[i][j])
return 0;
for (int i:v)
ve[f(i)].push_back(i);
for (int i=0;i<n;i++){
if (ve[i].size()<=1)
continue;
for (int j=0;j<ve[i].size();j++){
int u=ve[i][j],v=ve[i][(j+1)%ve[i].size()];
g[u][v]=g[v][u]=1;
}
}
build(g);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j=0;j<ve[i].size();j++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
162 ms |
24080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
162 ms |
24080 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
157 ms |
23956 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
77 ms |
14240 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
41 ms |
6228 KB |
Output is correct |
21 |
Correct |
168 ms |
23960 KB |
Output is correct |
22 |
Correct |
158 ms |
24228 KB |
Output is correct |
23 |
Correct |
161 ms |
24144 KB |
Output is correct |
24 |
Correct |
157 ms |
24216 KB |
Output is correct |
25 |
Correct |
65 ms |
14244 KB |
Output is correct |
26 |
Correct |
65 ms |
14100 KB |
Output is correct |
27 |
Correct |
162 ms |
24132 KB |
Output is correct |
28 |
Correct |
159 ms |
24272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
40 ms |
6424 KB |
Output is correct |
5 |
Correct |
164 ms |
24052 KB |
Output is correct |
6 |
Correct |
155 ms |
24128 KB |
Output is correct |
7 |
Correct |
161 ms |
24024 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
41 ms |
6432 KB |
Output is correct |
10 |
Correct |
156 ms |
24152 KB |
Output is correct |
11 |
Correct |
160 ms |
24144 KB |
Output is correct |
12 |
Correct |
166 ms |
23952 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
40 ms |
6488 KB |
Output is correct |
17 |
Correct |
165 ms |
24068 KB |
Output is correct |
18 |
Correct |
175 ms |
23932 KB |
Output is correct |
19 |
Correct |
162 ms |
24144 KB |
Output is correct |
20 |
Correct |
155 ms |
24064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
162 ms |
24080 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
157 ms |
23956 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
77 ms |
14240 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
41 ms |
6228 KB |
Output is correct |
21 |
Correct |
168 ms |
23960 KB |
Output is correct |
22 |
Correct |
158 ms |
24228 KB |
Output is correct |
23 |
Correct |
161 ms |
24144 KB |
Output is correct |
24 |
Correct |
157 ms |
24216 KB |
Output is correct |
25 |
Correct |
65 ms |
14244 KB |
Output is correct |
26 |
Correct |
65 ms |
14100 KB |
Output is correct |
27 |
Correct |
162 ms |
24132 KB |
Output is correct |
28 |
Correct |
159 ms |
24272 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Incorrect |
1 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
162 ms |
24080 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
157 ms |
23956 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
77 ms |
14240 KB |
Output is correct |
18 |
Correct |
0 ms |
600 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
41 ms |
6228 KB |
Output is correct |
21 |
Correct |
168 ms |
23960 KB |
Output is correct |
22 |
Correct |
158 ms |
24228 KB |
Output is correct |
23 |
Correct |
161 ms |
24144 KB |
Output is correct |
24 |
Correct |
157 ms |
24216 KB |
Output is correct |
25 |
Correct |
65 ms |
14244 KB |
Output is correct |
26 |
Correct |
65 ms |
14100 KB |
Output is correct |
27 |
Correct |
162 ms |
24132 KB |
Output is correct |
28 |
Correct |
159 ms |
24272 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Incorrect |
1 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |