#include "supertrees.h"
#include "bits/stdc++.h"
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define sz(x) ((int)((x).size()))
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int MxN=1e3+10;
int n, par[MxN], cyc[MxN];
bool v[MxN];
int fnd(int u) {
return par[u]=par[u]==u?u:fnd(par[u]);
}
void mrg(int a, int b) {
a=fnd(a); b=fnd(b);
if(a==b) return;
par[a]=b;
}
int construct(std::vector<std::vector<int>> p) {
n=sz(p);
FOR(i, 0, n) par[i]=i;
vector b(n, vector(n, 0));
FOR(i, 0, n) {
FOR(j, 0, n) {
int u=fnd(i);
if(p[i][j]==1) {
b[u][j]=b[j][u]=1;
mrg(i, j);
}
}
}
vector used(n, false);
FOR(i, 0, n) {
int u=fnd(i);
if(used[u]) continue;
used[u]=true;
cyc[u]=i;
int cn=1, lst=u, frst=u;
FOR(j, 0, n) {
int w=fnd(j);
if(used[w]) continue;
if(p[u][w]==2) {
used[w]=true;
cyc[w]=i;
cn++;
b[lst][w]=b[w][lst]=1;
lst=w;
}
}
b[lst][frst]=b[frst][lst]=1;
if(cn==2) {
return 0;
}
}
bool ok=true;
FOR(i, 0, n) {
FOR(j, 0, n) {
int u=fnd(i), w=fnd(j);
if(u==w) ok&=p[u][w]==1;
else if(cyc[u]==cyc[w]) ok&=p[u][w]==2;
else ok&=p[u][w]==0;
}
}
FOR(i, 0, n) b[i][i]=0;
if(!ok) return 0;
build(b);
return 1;
}
/*
Example 1:
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
Example 2:
2
1 0
0 1
Example 3:
2
1 3
3 1
5
1 1 2 2 2
1 1 2 2 2
2 2 1 2 2
2 2 2 1 1
2 2 2 1 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
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 |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
4 ms |
1116 KB |
Output is correct |
9 |
Correct |
126 ms |
21980 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
1112 KB |
Output is correct |
13 |
Correct |
105 ms |
21960 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
64 ms |
12048 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
25 ms |
5772 KB |
Output is correct |
22 |
Correct |
123 ms |
22044 KB |
Output is correct |
23 |
Correct |
102 ms |
22024 KB |
Output is correct |
24 |
Correct |
114 ms |
21972 KB |
Output is correct |
25 |
Correct |
48 ms |
12112 KB |
Output is correct |
26 |
Correct |
49 ms |
12044 KB |
Output is correct |
27 |
Correct |
114 ms |
22100 KB |
Output is correct |
28 |
Correct |
109 ms |
22096 KB |
Output is correct |
29 |
Correct |
55 ms |
12048 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 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 1 to 4, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |