#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;
if (gr[i].size()==1) continue;
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:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int j=0;j<gr[i].size()-1;j++)
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
23928 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
111 ms |
23936 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 |
59 ms |
13868 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
28 ms |
6300 KB |
Output is correct |
21 |
Correct |
113 ms |
23972 KB |
Output is correct |
22 |
Correct |
114 ms |
24000 KB |
Output is correct |
23 |
Correct |
121 ms |
23892 KB |
Output is correct |
24 |
Correct |
120 ms |
23808 KB |
Output is correct |
25 |
Correct |
51 ms |
13904 KB |
Output is correct |
26 |
Correct |
50 ms |
13908 KB |
Output is correct |
27 |
Correct |
119 ms |
23888 KB |
Output is correct |
28 |
Correct |
117 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
440 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1392 KB |
Output is correct |
9 |
Correct |
111 ms |
23892 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 |
1368 KB |
Output is correct |
13 |
Correct |
113 ms |
23788 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
65 ms |
14052 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 |
30 ms |
6340 KB |
Output is correct |
22 |
Correct |
114 ms |
24148 KB |
Output is correct |
23 |
Correct |
121 ms |
24076 KB |
Output is correct |
24 |
Correct |
130 ms |
24148 KB |
Output is correct |
25 |
Correct |
56 ms |
14256 KB |
Output is correct |
26 |
Correct |
54 ms |
14164 KB |
Output is correct |
27 |
Correct |
113 ms |
24080 KB |
Output is correct |
28 |
Correct |
119 ms |
23944 KB |
Output is correct |
29 |
Correct |
50 ms |
14164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
30 ms |
6220 KB |
Output is correct |
5 |
Correct |
119 ms |
23808 KB |
Output is correct |
6 |
Correct |
114 ms |
23884 KB |
Output is correct |
7 |
Correct |
121 ms |
23888 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
30 ms |
6220 KB |
Output is correct |
10 |
Correct |
115 ms |
24148 KB |
Output is correct |
11 |
Correct |
112 ms |
23892 KB |
Output is correct |
12 |
Correct |
122 ms |
24144 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
23928 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
111 ms |
23936 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 |
59 ms |
13868 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
28 ms |
6300 KB |
Output is correct |
21 |
Correct |
113 ms |
23972 KB |
Output is correct |
22 |
Correct |
114 ms |
24000 KB |
Output is correct |
23 |
Correct |
121 ms |
23892 KB |
Output is correct |
24 |
Correct |
120 ms |
23808 KB |
Output is correct |
25 |
Correct |
51 ms |
13904 KB |
Output is correct |
26 |
Correct |
50 ms |
13908 KB |
Output is correct |
27 |
Correct |
119 ms |
23888 KB |
Output is correct |
28 |
Correct |
117 ms |
23892 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 |
440 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1392 KB |
Output is correct |
37 |
Correct |
111 ms |
23892 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
113 ms |
23788 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
65 ms |
14052 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 |
30 ms |
6340 KB |
Output is correct |
50 |
Correct |
114 ms |
24148 KB |
Output is correct |
51 |
Correct |
121 ms |
24076 KB |
Output is correct |
52 |
Correct |
130 ms |
24148 KB |
Output is correct |
53 |
Correct |
56 ms |
14256 KB |
Output is correct |
54 |
Correct |
54 ms |
14164 KB |
Output is correct |
55 |
Correct |
113 ms |
24080 KB |
Output is correct |
56 |
Correct |
119 ms |
23944 KB |
Output is correct |
57 |
Correct |
50 ms |
14164 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
59 ms |
14204 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Incorrect |
1 ms |
348 KB |
Too many ways to get from 0 to 9, should be 1 found no less than 2 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
113 ms |
23928 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
111 ms |
23936 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 |
59 ms |
13868 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
28 ms |
6300 KB |
Output is correct |
21 |
Correct |
113 ms |
23972 KB |
Output is correct |
22 |
Correct |
114 ms |
24000 KB |
Output is correct |
23 |
Correct |
121 ms |
23892 KB |
Output is correct |
24 |
Correct |
120 ms |
23808 KB |
Output is correct |
25 |
Correct |
51 ms |
13904 KB |
Output is correct |
26 |
Correct |
50 ms |
13908 KB |
Output is correct |
27 |
Correct |
119 ms |
23888 KB |
Output is correct |
28 |
Correct |
117 ms |
23892 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 |
440 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1392 KB |
Output is correct |
37 |
Correct |
111 ms |
23892 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
113 ms |
23788 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
65 ms |
14052 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 |
30 ms |
6340 KB |
Output is correct |
50 |
Correct |
114 ms |
24148 KB |
Output is correct |
51 |
Correct |
121 ms |
24076 KB |
Output is correct |
52 |
Correct |
130 ms |
24148 KB |
Output is correct |
53 |
Correct |
56 ms |
14256 KB |
Output is correct |
54 |
Correct |
54 ms |
14164 KB |
Output is correct |
55 |
Correct |
113 ms |
24080 KB |
Output is correct |
56 |
Correct |
119 ms |
23944 KB |
Output is correct |
57 |
Correct |
50 ms |
14164 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
30 ms |
6220 KB |
Output is correct |
62 |
Correct |
119 ms |
23808 KB |
Output is correct |
63 |
Correct |
114 ms |
23884 KB |
Output is correct |
64 |
Correct |
121 ms |
23888 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
30 ms |
6220 KB |
Output is correct |
67 |
Correct |
115 ms |
24148 KB |
Output is correct |
68 |
Correct |
112 ms |
23892 KB |
Output is correct |
69 |
Correct |
122 ms |
24144 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 4 to 8, should be 1 found no less than 2 |
72 |
Halted |
0 ms |
0 KB |
- |