#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<int> par(1015),sz(1015,1);
int findPar(int u){
if(par[u]==u) return u;
return par[u]=findPar(par[u]);
}
void unite(int u,int v){
int ulp=findPar(u);
int vlp=findPar(v);
if(ulp==vlp) return;
if(sz[ulp]>sz[vlp]){
par[vlp]=ulp;
sz[ulp]+=sz[vlp];
}else{
par[ulp]=vlp;
sz[vlp]+=sz[ulp];
}
}
bool is_samee(int u,int v){
return findPar(u)==findPar(v);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> adj(n,vector<int>(n,0));
for(int i=0;i<n;++i) par[i]=i;
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
if(p[i][j]>0) unite(i,j);
}
}
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
if(p[i][j]==0&&is_samee(i,j)){
return 0;
}
}
}
vector<int> last(n+1,-1);
for(int i=0;i<n;++i){
int ulp=findPar(i);
if(last[ulp]!=-1){
adj[i][last[ulp]]=1;
adj[last[ulp]][i]=1;
}
last[ulp]=i;
}
build(adj);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
117 ms |
24064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
117 ms |
24064 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1340 KB |
Output is correct |
13 |
Correct |
112 ms |
24144 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
62 ms |
14084 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6236 KB |
Output is correct |
21 |
Correct |
120 ms |
24148 KB |
Output is correct |
22 |
Correct |
116 ms |
24144 KB |
Output is correct |
23 |
Correct |
122 ms |
24144 KB |
Output is correct |
24 |
Correct |
113 ms |
24076 KB |
Output is correct |
25 |
Correct |
55 ms |
14092 KB |
Output is correct |
26 |
Correct |
49 ms |
14216 KB |
Output is correct |
27 |
Correct |
123 ms |
24144 KB |
Output is correct |
28 |
Correct |
140 ms |
24144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
117 ms |
24064 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1340 KB |
Output is correct |
13 |
Correct |
112 ms |
24144 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
62 ms |
14084 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6236 KB |
Output is correct |
21 |
Correct |
120 ms |
24148 KB |
Output is correct |
22 |
Correct |
116 ms |
24144 KB |
Output is correct |
23 |
Correct |
122 ms |
24144 KB |
Output is correct |
24 |
Correct |
113 ms |
24076 KB |
Output is correct |
25 |
Correct |
55 ms |
14092 KB |
Output is correct |
26 |
Correct |
49 ms |
14216 KB |
Output is correct |
27 |
Correct |
123 ms |
24144 KB |
Output is correct |
28 |
Correct |
140 ms |
24144 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
117 ms |
24064 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1340 KB |
Output is correct |
13 |
Correct |
112 ms |
24144 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
860 KB |
Output is correct |
17 |
Correct |
62 ms |
14084 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
31 ms |
6236 KB |
Output is correct |
21 |
Correct |
120 ms |
24148 KB |
Output is correct |
22 |
Correct |
116 ms |
24144 KB |
Output is correct |
23 |
Correct |
122 ms |
24144 KB |
Output is correct |
24 |
Correct |
113 ms |
24076 KB |
Output is correct |
25 |
Correct |
55 ms |
14092 KB |
Output is correct |
26 |
Correct |
49 ms |
14216 KB |
Output is correct |
27 |
Correct |
123 ms |
24144 KB |
Output is correct |
28 |
Correct |
140 ms |
24144 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 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 |
- |