#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector < int > adj[1002];
int ataman[10002], used[1002];
int Get(int x) {
if ( x == ataman[x]) return x;
return ataman[x] = Get(ataman[x]);
}
void Unite(int x, int y) {
x = Get(x);
y = Get(y);
if (x == y) return ;
if ( x < y) swap(x, y);
ataman[x]= y;
}
int construct(vector<vector<int>> a) {
int n = a.size(), i, j;
vector < vector < int > > ans(n, vector<int>(n, 0));
for (i = 0; i < n; i ++) ataman[i]= i;
int s = 1;
for ( i = 0; i < n; i++) {
for ( j = 0; j < n; j ++) {
if ( a[i][j] != 0 && i != j) Unite(i, j);
}
}
for (i = 0; i < n; i ++) {
for (j = 0; j < n; j ++) {
if ( i == j) continue;
if ( a[i][j] == 0 && Get(i) == Get(j)) s= 0;
if ( a[i][j] != 0 && Get(i) != Get(j)) s = 0;
}
}
for (i = 0; i < n; i ++) {
vector < int > v;
v.push_back(i);
for (j = i + 1; j < n; j ++) {
if ( Get(j) == Get(i) && !used[j]) v.push_back(j);
}
used[i] = 1;
for (j = 1; j < v.size(); j ++) {
used[v[j]] = 1;
ans[v[j]][v[j - 1]] = ans[v[j - 1]][v[j]] = 1;
}
}
if ( s == 0) return 0;
build(ans);
return s;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (j = 1; j < v.size(); 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 |
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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
183 ms |
22060 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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
183 ms |
22060 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1116 KB |
Output is correct |
13 |
Correct |
158 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
86 ms |
13568 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
40 ms |
6424 KB |
Output is correct |
21 |
Correct |
162 ms |
23280 KB |
Output is correct |
22 |
Correct |
167 ms |
23544 KB |
Output is correct |
23 |
Correct |
168 ms |
23308 KB |
Output is correct |
24 |
Correct |
162 ms |
23380 KB |
Output is correct |
25 |
Correct |
75 ms |
13392 KB |
Output is correct |
26 |
Correct |
72 ms |
13392 KB |
Output is correct |
27 |
Correct |
164 ms |
23488 KB |
Output is correct |
28 |
Correct |
161 ms |
23380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
0 ms |
600 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
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 |
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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
183 ms |
22060 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1116 KB |
Output is correct |
13 |
Correct |
158 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
86 ms |
13568 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
40 ms |
6424 KB |
Output is correct |
21 |
Correct |
162 ms |
23280 KB |
Output is correct |
22 |
Correct |
167 ms |
23544 KB |
Output is correct |
23 |
Correct |
168 ms |
23308 KB |
Output is correct |
24 |
Correct |
162 ms |
23380 KB |
Output is correct |
25 |
Correct |
75 ms |
13392 KB |
Output is correct |
26 |
Correct |
72 ms |
13392 KB |
Output is correct |
27 |
Correct |
164 ms |
23488 KB |
Output is correct |
28 |
Correct |
161 ms |
23380 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Incorrect |
0 ms |
600 KB |
Answer gives possible 1 while actual possible 0 |
33 |
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 |
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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
183 ms |
22060 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1116 KB |
Output is correct |
13 |
Correct |
158 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
86 ms |
13568 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
40 ms |
6424 KB |
Output is correct |
21 |
Correct |
162 ms |
23280 KB |
Output is correct |
22 |
Correct |
167 ms |
23544 KB |
Output is correct |
23 |
Correct |
168 ms |
23308 KB |
Output is correct |
24 |
Correct |
162 ms |
23380 KB |
Output is correct |
25 |
Correct |
75 ms |
13392 KB |
Output is correct |
26 |
Correct |
72 ms |
13392 KB |
Output is correct |
27 |
Correct |
164 ms |
23488 KB |
Output is correct |
28 |
Correct |
161 ms |
23380 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Incorrect |
0 ms |
600 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |