#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define what_is(a) cout<< #a << " is " << a << "\n"
#define checker(a) cout << "checker reached " <<a << "\n"
const int maxn = 1000;
struct subset{
int parent,rank;
}subsets[maxn];
int find(int a){
if(subsets[a].parent==a)return a;
subsets[a].parent = find(subsets[a].parent);
return subsets[a].parent;
}
void Union(int a,int b){
a = find(subsets[a].parent),b = find(subsets[b].parent);
if(a==b)return;
if(subsets[a].rank<subsets[b].rank)
subsets[a].parent = b;
else if(subsets[a].rank>subsets[b].rank)
subsets[b].parent = a;
else{
subsets[a].parent = b;
subsets[b].rank++;
}
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
for(int i=0;i<n;i++)subsets[i] = {i,0};
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
if(p[i][j]==0)continue;
Union(i,j);
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(p[i][j]==0&&find(i)==find(j)){
return 0;
}
vector<vector<int>> sets(n,vector<int>());
for(int i=0;i<n;i++)
sets[find(i)].push_back(i);
vector<vector<int>> g(n,vector<int>());
for(int i=0;i<n;i++){
vector<int> vec(n,0);
g[i] = vec;
}
for(vector<int> st : sets){
if(st.size()<=1)continue;
for(int i=0;i<(int)st.size()-1;i++)
g[st[i]][st[i+1]] = g[st[i+1]][st[i]] = 1;
}
build(g);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1092 KB |
Output is correct |
7 |
Correct |
248 ms |
22012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1092 KB |
Output is correct |
7 |
Correct |
248 ms |
22012 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
230 ms |
24056 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
120 ms |
10092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
71 ms |
6264 KB |
Output is correct |
21 |
Correct |
252 ms |
24044 KB |
Output is correct |
22 |
Correct |
237 ms |
23916 KB |
Output is correct |
23 |
Correct |
241 ms |
24016 KB |
Output is correct |
24 |
Correct |
236 ms |
23992 KB |
Output is correct |
25 |
Correct |
102 ms |
10104 KB |
Output is correct |
26 |
Correct |
98 ms |
10064 KB |
Output is correct |
27 |
Correct |
256 ms |
24036 KB |
Output is correct |
28 |
Correct |
237 ms |
24004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 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 |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 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 |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1092 KB |
Output is correct |
7 |
Correct |
248 ms |
22012 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
230 ms |
24056 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
120 ms |
10092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
71 ms |
6264 KB |
Output is correct |
21 |
Correct |
252 ms |
24044 KB |
Output is correct |
22 |
Correct |
237 ms |
23916 KB |
Output is correct |
23 |
Correct |
241 ms |
24016 KB |
Output is correct |
24 |
Correct |
236 ms |
23992 KB |
Output is correct |
25 |
Correct |
102 ms |
10104 KB |
Output is correct |
26 |
Correct |
98 ms |
10064 KB |
Output is correct |
27 |
Correct |
256 ms |
24036 KB |
Output is correct |
28 |
Correct |
237 ms |
24004 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Incorrect |
1 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1092 KB |
Output is correct |
7 |
Correct |
248 ms |
22012 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
10 ms |
1228 KB |
Output is correct |
13 |
Correct |
230 ms |
24056 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
120 ms |
10092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
71 ms |
6264 KB |
Output is correct |
21 |
Correct |
252 ms |
24044 KB |
Output is correct |
22 |
Correct |
237 ms |
23916 KB |
Output is correct |
23 |
Correct |
241 ms |
24016 KB |
Output is correct |
24 |
Correct |
236 ms |
23992 KB |
Output is correct |
25 |
Correct |
102 ms |
10104 KB |
Output is correct |
26 |
Correct |
98 ms |
10064 KB |
Output is correct |
27 |
Correct |
256 ms |
24036 KB |
Output is correct |
28 |
Correct |
237 ms |
24004 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Incorrect |
1 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |