#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) {
if(fnd(i)==fnd(j)) continue;
if(p[i][j]==1) {
b[i][j]=b[j][i]=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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
408 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
98 ms |
23980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
408 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
98 ms |
23980 KB |
Output is correct |
8 |
Correct |
1 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 |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
99 ms |
24152 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
1116 KB |
Output is correct |
9 |
Correct |
99 ms |
22100 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
1116 KB |
Output is correct |
13 |
Correct |
96 ms |
22044 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
46 ms |
12116 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 |
26 ms |
5748 KB |
Output is correct |
22 |
Correct |
99 ms |
22096 KB |
Output is correct |
23 |
Correct |
102 ms |
22024 KB |
Output is correct |
24 |
Correct |
103 ms |
22040 KB |
Output is correct |
25 |
Correct |
41 ms |
12116 KB |
Output is correct |
26 |
Correct |
44 ms |
12116 KB |
Output is correct |
27 |
Correct |
102 ms |
22100 KB |
Output is correct |
28 |
Correct |
102 ms |
22040 KB |
Output is correct |
29 |
Correct |
41 ms |
12116 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 |
Correct |
26 ms |
6156 KB |
Output is correct |
5 |
Correct |
107 ms |
24148 KB |
Output is correct |
6 |
Correct |
107 ms |
24148 KB |
Output is correct |
7 |
Correct |
109 ms |
24020 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
24 ms |
6244 KB |
Output is correct |
10 |
Correct |
97 ms |
23948 KB |
Output is correct |
11 |
Correct |
96 ms |
24144 KB |
Output is correct |
12 |
Correct |
105 ms |
23892 KB |
Output is correct |
13 |
Correct |
1 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 |
26 ms |
6316 KB |
Output is correct |
17 |
Correct |
101 ms |
23948 KB |
Output is correct |
18 |
Correct |
118 ms |
24000 KB |
Output is correct |
19 |
Correct |
99 ms |
23984 KB |
Output is correct |
20 |
Correct |
107 ms |
23896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
408 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
98 ms |
23980 KB |
Output is correct |
8 |
Correct |
1 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 |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
99 ms |
24152 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
408 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
98 ms |
23980 KB |
Output is correct |
8 |
Correct |
1 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 |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
99 ms |
24152 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |