#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
struct DSU{
vector<int>e;
vector<int>storage[1005];
void init(int n){
e=vector<int>(n,-1);
for(int x=0;x<n;x++){
storage[x].push_back(x);
}
}
int get(int x){return e[x]<0?x:e[x]=get(e[x]);}\
bool sameSet(int x, int y){return get(x)==get(y);}
bool unite(int x, int y){
x=get(x);
y=get(y);
if(x==y) return 0;
if(e[x]>e[y]) swap(x,y);
e[x]+=e[y];
for(auto it:storage[y]) storage[x].push_back(it);
e[y]=x;
return 1;
}
};
int construct(vector<vector<int>> p) {
//int n = p.size();
//std::vector<std::vector<int>> answer;
//for (int i = 0; i < n; i++) {
//std::vector<int> row;
//row.resize(n);
//answer.push_back(row);
//}
//build(answer);
//return 1;
int n=p.size();
DSU one;
one.init(n+5);
for(int x=0;x<n;x++){
for(int y=0;y<n;y++){
if(p[x][y]==1){
one.unite(x,y);
}
}
}
vector<vector<int>>ans;
ans.resize(n);
for(int x=0;x<n;x++){
for(int y=0;y<n;y++){
ans[x].push_back(0);
}
}
for(int x=0;x<n;x++){
if(one.get(x)==x){
int last=-1;
for(auto it:one.storage[x]){
if(last!=-1){
ans[last][it]=1;
ans[it][last]=1;
}
last=it;
}
}
}
for(int x=0;x<n;x++){
for(int y=0;y<n;y++){
if(p[x][y]==0&&one.sameSet(x,y)) return 0;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
7 ms |
1472 KB |
Output is correct |
7 |
Correct |
163 ms |
24144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
7 ms |
1472 KB |
Output is correct |
7 |
Correct |
163 ms |
24144 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 |
8 ms |
1440 KB |
Output is correct |
13 |
Correct |
153 ms |
24196 KB |
Output is correct |
14 |
Correct |
1 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 |
74 ms |
14200 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6260 KB |
Output is correct |
21 |
Correct |
155 ms |
24076 KB |
Output is correct |
22 |
Correct |
155 ms |
24152 KB |
Output is correct |
23 |
Correct |
165 ms |
24400 KB |
Output is correct |
24 |
Correct |
173 ms |
24144 KB |
Output is correct |
25 |
Correct |
64 ms |
14164 KB |
Output is correct |
26 |
Correct |
62 ms |
14344 KB |
Output is correct |
27 |
Correct |
159 ms |
24144 KB |
Output is correct |
28 |
Correct |
157 ms |
24148 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 |
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 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
7 ms |
1472 KB |
Output is correct |
7 |
Correct |
163 ms |
24144 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 |
8 ms |
1440 KB |
Output is correct |
13 |
Correct |
153 ms |
24196 KB |
Output is correct |
14 |
Correct |
1 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 |
74 ms |
14200 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6260 KB |
Output is correct |
21 |
Correct |
155 ms |
24076 KB |
Output is correct |
22 |
Correct |
155 ms |
24152 KB |
Output is correct |
23 |
Correct |
165 ms |
24400 KB |
Output is correct |
24 |
Correct |
173 ms |
24144 KB |
Output is correct |
25 |
Correct |
64 ms |
14164 KB |
Output is correct |
26 |
Correct |
62 ms |
14344 KB |
Output is correct |
27 |
Correct |
159 ms |
24144 KB |
Output is correct |
28 |
Correct |
157 ms |
24148 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
7 ms |
1472 KB |
Output is correct |
7 |
Correct |
163 ms |
24144 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 |
8 ms |
1440 KB |
Output is correct |
13 |
Correct |
153 ms |
24196 KB |
Output is correct |
14 |
Correct |
1 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 |
74 ms |
14200 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
6260 KB |
Output is correct |
21 |
Correct |
155 ms |
24076 KB |
Output is correct |
22 |
Correct |
155 ms |
24152 KB |
Output is correct |
23 |
Correct |
165 ms |
24400 KB |
Output is correct |
24 |
Correct |
173 ms |
24144 KB |
Output is correct |
25 |
Correct |
64 ms |
14164 KB |
Output is correct |
26 |
Correct |
62 ms |
14344 KB |
Output is correct |
27 |
Correct |
159 ms |
24144 KB |
Output is correct |
28 |
Correct |
157 ms |
24148 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |