#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int N=1e3+9;
vector<int> rnk(N,0),par(N);
int ulp(int node){
if(par[node]==node) return node;
return par[node]=ulp(par[node]);
}
void spajaj(int a,int b){
a=ulp(a);b=ulp(b);
if(a==b) return;
if(rnk[b]>rnk[a])
swap(a,b);
par[b]=a;
if(rnk[a]==rnk[b])
rnk[a]++;
}
int construct(std::vector<std::vector<int>> p){
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);
}
vector<set<int>> lanci(n);
for(int i=0; i<n; i++) par[i]=i;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]==1)
spajaj(i,j);
if(p[i][j]==3) return 0;
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]==1){
lanci[ulp(i)].insert(j);
lanci[ulp(i)].insert(i);
}
if(ulp(i)==ulp(j)&&p[i][j]!=1)
return 0;
}
}
for(int i=0; i<n; i++){
if(lanci[i].size()<=1) continue;
for(auto it=next(lanci[i].begin()); it!=lanci[i].end(); it++){
answer[*prev(it)][*it]=1;
answer[*it][*prev(it)]=1;
}
}
vector<int> br_poj_predstavnika(n,0);
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(p[i][j]!=2) continue;
if(br_poj_predstavnika[ulp(i)]==2||br_poj_predstavnika[ulp(j)]==2) continue;
//cout << i << " " << j << endl;
br_poj_predstavnika[ulp(i)]++;
br_poj_predstavnika[ulp(j)]++;
answer[ulp(i)][ulp(j)]=1;
answer[ulp(j)][ulp(i)]=1;
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
227 ms |
24056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
227 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
1372 KB |
Output is correct |
13 |
Correct |
163 ms |
24068 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
940 KB |
Output is correct |
17 |
Correct |
77 ms |
14080 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 |
6236 KB |
Output is correct |
21 |
Correct |
169 ms |
24148 KB |
Output is correct |
22 |
Correct |
165 ms |
24068 KB |
Output is correct |
23 |
Correct |
198 ms |
24076 KB |
Output is correct |
24 |
Correct |
161 ms |
24208 KB |
Output is correct |
25 |
Correct |
68 ms |
14096 KB |
Output is correct |
26 |
Correct |
78 ms |
14088 KB |
Output is correct |
27 |
Correct |
213 ms |
24148 KB |
Output is correct |
28 |
Correct |
163 ms |
24204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
440 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
41 ms |
6420 KB |
Output is correct |
5 |
Correct |
190 ms |
24080 KB |
Output is correct |
6 |
Correct |
190 ms |
24048 KB |
Output is correct |
7 |
Correct |
193 ms |
24148 KB |
Output is correct |
8 |
Incorrect |
1 ms |
344 KB |
Too few ways to get from 0 to 3, should be 2 found 0 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
227 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
1372 KB |
Output is correct |
13 |
Correct |
163 ms |
24068 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
940 KB |
Output is correct |
17 |
Correct |
77 ms |
14080 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 |
6236 KB |
Output is correct |
21 |
Correct |
169 ms |
24148 KB |
Output is correct |
22 |
Correct |
165 ms |
24068 KB |
Output is correct |
23 |
Correct |
198 ms |
24076 KB |
Output is correct |
24 |
Correct |
161 ms |
24208 KB |
Output is correct |
25 |
Correct |
68 ms |
14096 KB |
Output is correct |
26 |
Correct |
78 ms |
14088 KB |
Output is correct |
27 |
Correct |
213 ms |
24148 KB |
Output is correct |
28 |
Correct |
163 ms |
24204 KB |
Output is correct |
29 |
Correct |
1 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 |
440 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
227 ms |
24056 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
10 ms |
1372 KB |
Output is correct |
13 |
Correct |
163 ms |
24068 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
940 KB |
Output is correct |
17 |
Correct |
77 ms |
14080 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 |
6236 KB |
Output is correct |
21 |
Correct |
169 ms |
24148 KB |
Output is correct |
22 |
Correct |
165 ms |
24068 KB |
Output is correct |
23 |
Correct |
198 ms |
24076 KB |
Output is correct |
24 |
Correct |
161 ms |
24208 KB |
Output is correct |
25 |
Correct |
68 ms |
14096 KB |
Output is correct |
26 |
Correct |
78 ms |
14088 KB |
Output is correct |
27 |
Correct |
213 ms |
24148 KB |
Output is correct |
28 |
Correct |
163 ms |
24204 KB |
Output is correct |
29 |
Correct |
1 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 |
440 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |