#include "supertrees.h"
#include <vector>
using namespace std;
const int NMAX = 1000;
vector <int> adj[NMAX + 1];
int par[NMAX + 1];
int Find(int x){
if(x == par[x]){
return x;
}
return par[x] = Find(par[x]);
}
void Unite(int i, int j){
i = Find(i);
j = Find(j);
par[i] = j;
}
int rep[NMAX + 1];
vector <int> gr[NMAX + 1];
int construct(vector<vector<int>> p) {
int n = p.size();
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(i == j && p[i][j] != 1){
return 0;
}
if(i != j && p[i][j] == 1 && Find(i) != Find(j)){
adj[i].push_back(j);
adj[j].push_back(i);
Unite(i, j);
}else if(p[i][j] == 3){
return 0;
}
}
}
for(int i = 0; i < n; i++){
rep[i] = par[i];
par[i] = i;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(rep[i] == rep[j] && p[i][j] != 1){
return 0;
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 2){
if(rep[i] == rep[j]){
return 0;
}
Unite(rep[i], rep[j]);
}
}
}
for(int i = 0; i < n; i++){
gr[Find(i)].push_back(i);
}
for(int i = 0; i < n; i++){
if((int)gr[i].size() >= 3){
for(int j = 1; j < (int)gr[i].size(); j++){
adj[gr[i][j]].push_back(gr[i][j - 1]);
adj[gr[i][j - 1]].push_back(gr[i][j]);
}
adj[gr[i].back()].push_back(gr[i][0]);
adj[gr[i][0]].push_back(gr[i].back());
}else{
if((int)gr[i].size() == 2){
return 0;
}
}
}
vector <vector <int>> ans(n, vector <int> (n, 0));
for(int i = 0; i < n; i++){
for(int x : adj[i]){
ans[i][x] = 1;
}
}
build(ans);
return 1;
}
/*
5
1 1 1 2 2
1 1 1 2 2
1 1 1 2 2
2 2 2 1 2
2 2 2 2 1
*/
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
147 ms |
22100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
147 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
149 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
79 ms |
8240 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1304 KB |
Output is correct |
9 |
Correct |
147 ms |
22060 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1304 KB |
Output is correct |
13 |
Correct |
160 ms |
22064 KB |
Output is correct |
14 |
Incorrect |
0 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
38 ms |
5832 KB |
Output is correct |
5 |
Correct |
151 ms |
22264 KB |
Output is correct |
6 |
Correct |
150 ms |
22140 KB |
Output is correct |
7 |
Correct |
175 ms |
22252 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
37 ms |
5728 KB |
Output is correct |
10 |
Correct |
146 ms |
22224 KB |
Output is correct |
11 |
Correct |
146 ms |
22088 KB |
Output is correct |
12 |
Correct |
173 ms |
22212 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
37 ms |
5712 KB |
Output is correct |
17 |
Correct |
148 ms |
22212 KB |
Output is correct |
18 |
Correct |
148 ms |
22100 KB |
Output is correct |
19 |
Correct |
153 ms |
22080 KB |
Output is correct |
20 |
Correct |
142 ms |
22100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
147 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
149 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
79 ms |
8240 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
147 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
149 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
604 KB |
Output is correct |
17 |
Correct |
79 ms |
8240 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
19 |
Halted |
0 ms |
0 KB |
- |