#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;
for (int i=0;i<n;i++) {
for (int j=i+1;j<n;j++) {
if (paths[i][j]) Union(i, j);
}
}
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()) {
int x=gr[i][0];
for (auto y:gr[i])
if (x!=y) a[x][y]=1, a[y][x]=1;
}
}
build(a);
return 1;
}
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
112 ms |
24108 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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
112 ms |
24108 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1380 KB |
Output is correct |
13 |
Correct |
113 ms |
24188 KB |
Output is correct |
14 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
112 ms |
24108 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1380 KB |
Output is correct |
13 |
Correct |
113 ms |
24188 KB |
Output is correct |
14 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
112 ms |
24108 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1380 KB |
Output is correct |
13 |
Correct |
113 ms |
24188 KB |
Output is correct |
14 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |