#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int parent[1005], sz[1005];
int Find(int x) {
if (x==parent[x])
return x;
return parent[x]=Find(parent[x]);
}
void Union(int a, int b) {
a=Find(a), b=Find(b);
if (a==b) return;
if (sz[a]<sz[b])
swap(a, b);
sz[a]+=sz[b];
parent[b]=a;
}
int construct(vector<vector<int> > paths) {
int n=paths.size();
vector<vector<int> > a=paths;
for (int i=0;i<n;i++)
sz[i]=1, parent[i]=i;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
a[i][j]=0;
bool vtor_subtask=true;
for (int i=0;i<n;i++) {
for (int j=i+1;j<n;j++) {
if (paths[i][j]) Union(i, j);
if (paths[i][j]==2) vtor_subtask=false;
}
}
vector<int> gr[n];
for (int i=0;i<n;i++) {
int lider=Find(i);
gr[lider].push_back(i);
}
for (int i=0;i<n;i++) {
if (gr[i].size()) {
for (auto x:gr[i])
for (auto y:gr[i])
if (!paths[x][y])
return 0;
if (vtor_subtask) {
int x=gr[i][0];
for (auto y:gr[i])
if (x!=y) a[x][y]=1, a[y][x]=1;
}
else {
if (gr[i].size()==2) return 0;
int x=gr[i][0], y=gr[i][gr[i].size()-1];
for (int j=0;j<gr[i].size()-1;j++)
a[gr[i][j]][gr[i][j+1]]=1, a[gr[i][j+1]][gr[i][j]]=1;
a[x][y]=1, a[y][x]=1;
}
}
}
build(a);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j=0;j<gr[i].size()-1;j++)
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
115 ms |
23940 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 |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
115 ms |
23940 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 |
5 ms |
1192 KB |
Output is correct |
13 |
Correct |
117 ms |
24076 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 |
58 ms |
14252 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
30 ms |
6268 KB |
Output is correct |
21 |
Correct |
127 ms |
24144 KB |
Output is correct |
22 |
Correct |
118 ms |
24060 KB |
Output is correct |
23 |
Correct |
131 ms |
24144 KB |
Output is correct |
24 |
Correct |
122 ms |
24144 KB |
Output is correct |
25 |
Correct |
59 ms |
14160 KB |
Output is correct |
26 |
Correct |
48 ms |
14160 KB |
Output is correct |
27 |
Correct |
123 ms |
24148 KB |
Output is correct |
28 |
Correct |
118 ms |
24144 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 |
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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
1372 KB |
Output is correct |
9 |
Correct |
116 ms |
23800 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
116 ms |
24144 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
57 ms |
14212 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
0 ms |
348 KB |
b[4][4] is not 0 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
31 ms |
6324 KB |
Output is correct |
5 |
Correct |
126 ms |
23988 KB |
Output is correct |
6 |
Correct |
128 ms |
24148 KB |
Output is correct |
7 |
Correct |
123 ms |
24144 KB |
Output is correct |
8 |
Incorrect |
1 ms |
344 KB |
b[4][4] is not 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
115 ms |
23940 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 |
5 ms |
1192 KB |
Output is correct |
13 |
Correct |
117 ms |
24076 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 |
58 ms |
14252 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
30 ms |
6268 KB |
Output is correct |
21 |
Correct |
127 ms |
24144 KB |
Output is correct |
22 |
Correct |
118 ms |
24060 KB |
Output is correct |
23 |
Correct |
131 ms |
24144 KB |
Output is correct |
24 |
Correct |
122 ms |
24144 KB |
Output is correct |
25 |
Correct |
59 ms |
14160 KB |
Output is correct |
26 |
Correct |
48 ms |
14160 KB |
Output is correct |
27 |
Correct |
123 ms |
24148 KB |
Output is correct |
28 |
Correct |
118 ms |
24144 KB |
Output is correct |
29 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
116 ms |
23800 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
5 ms |
1372 KB |
Output is correct |
41 |
Correct |
116 ms |
24144 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
57 ms |
14212 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
b[4][4] is not 0 |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
115 ms |
23940 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 |
5 ms |
1192 KB |
Output is correct |
13 |
Correct |
117 ms |
24076 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 |
58 ms |
14252 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
30 ms |
6268 KB |
Output is correct |
21 |
Correct |
127 ms |
24144 KB |
Output is correct |
22 |
Correct |
118 ms |
24060 KB |
Output is correct |
23 |
Correct |
131 ms |
24144 KB |
Output is correct |
24 |
Correct |
122 ms |
24144 KB |
Output is correct |
25 |
Correct |
59 ms |
14160 KB |
Output is correct |
26 |
Correct |
48 ms |
14160 KB |
Output is correct |
27 |
Correct |
123 ms |
24148 KB |
Output is correct |
28 |
Correct |
118 ms |
24144 KB |
Output is correct |
29 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
116 ms |
23800 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
5 ms |
1372 KB |
Output is correct |
41 |
Correct |
116 ms |
24144 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
57 ms |
14212 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Incorrect |
0 ms |
348 KB |
b[4][4] is not 0 |
49 |
Halted |
0 ms |
0 KB |
- |