#include "supertrees.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e18;
const int mod = 1e9+7;
const int maxn = 1000 + 1;
vector<int> g[maxn];
int x;
int h[maxn], oh[maxn], used[maxn];
bool two[maxn], three[maxn];
bool was[maxn];
void dfs(int v){
h[v] = x;
was[v] = 1;
for(auto i : g[v]){
if(!was[i]){
dfs(i);
}
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n);
for(int i = 0; i < n; i++)ans[i].resize(n);
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
if(i == j){
if(p[i][i] != 1)return 0;
continue;
}
if(p[i][j]){
g[j].pb(i);
g[i].pb(j);
}
if(p[i][j] != p[j][i]){
return 0;
}
}
}
for(int i = 0; i < n; i++){
if(!was[i]){
x = i;
dfs(i);
}
}
for(int i = 0; i < n; i++){
oh[i] = used[i] = -1;
for(int j = 0; j < n; j++){
if(h[i] == h[j] && p[i][j] == 0){
return 0;
}
if(h[i] == h[j]){
if(p[i][j] == 2){
two[h[i]] = 1;
}
else if(p[i][j] == 3){
three[h[i]] = 1;
}
if(two[h[i]] && three[h[i]]){
return 0;
}
}
}
}
vt<int> unq;
for(int i = 0; i < n; i++){
if(oh[i] == -1){
unq.pb(i);
oh[i] = i;
for(auto j : g[i]){
if(p[i][j] == 1){
if(oh[j] != -1){
return 0;
}
oh[j] = i;
ans[i][j] = ans[j][i] = 1;
}
}
}
}
int sz = unq.size();
for(int I = 0; I < sz; I++){
int i = unq[I];
if(used[i] != -1)continue;
used[i] = i;
if(h[i] != i)return 0;
if(!three[i] && !two[i])continue;
bool wt = 0;
if(three[i])wt = 1;
int o = -1, ls = -1, z = -1;
for(int J = 0; J < sz; J++){
int j = unq[J];
if(p[i][j] > 1 && used[j] == -1){
used[j] = i;
if(o == -1){
o = j;
ans[i][o] = ans[o][i] = 1;
}
else {
if(ls == -1)ls = z;
ans[z][j] = ans[j][z] = 1;
z = j;
}
}
else if(p[i][j] > 1)return 0;
}
if(z == -1)return 0;
ans[o][z] = ans[z][o] = 1;
if(wt && z == ls){
return 0;
}
else if(wt){
ans[z][i] = ans[i][z] = 1;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1628 KB |
Output is correct |
7 |
Correct |
159 ms |
28048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1628 KB |
Output is correct |
7 |
Correct |
159 ms |
28048 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
164 ms |
24100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
73 ms |
16840 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
6228 KB |
Output is correct |
21 |
Correct |
153 ms |
24612 KB |
Output is correct |
22 |
Correct |
152 ms |
23976 KB |
Output is correct |
23 |
Correct |
158 ms |
26148 KB |
Output is correct |
24 |
Correct |
150 ms |
24008 KB |
Output is correct |
25 |
Correct |
70 ms |
14624 KB |
Output is correct |
26 |
Correct |
66 ms |
14168 KB |
Output is correct |
27 |
Correct |
160 ms |
27292 KB |
Output is correct |
28 |
Correct |
158 ms |
24036 KB |
Output is correct |
# |
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 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1628 KB |
Output is correct |
7 |
Correct |
159 ms |
28048 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
164 ms |
24100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
73 ms |
16840 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
6228 KB |
Output is correct |
21 |
Correct |
153 ms |
24612 KB |
Output is correct |
22 |
Correct |
152 ms |
23976 KB |
Output is correct |
23 |
Correct |
158 ms |
26148 KB |
Output is correct |
24 |
Correct |
150 ms |
24008 KB |
Output is correct |
25 |
Correct |
70 ms |
14624 KB |
Output is correct |
26 |
Correct |
66 ms |
14168 KB |
Output is correct |
27 |
Correct |
160 ms |
27292 KB |
Output is correct |
28 |
Correct |
158 ms |
24036 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1628 KB |
Output is correct |
7 |
Correct |
159 ms |
28048 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
164 ms |
24100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
73 ms |
16840 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
6228 KB |
Output is correct |
21 |
Correct |
153 ms |
24612 KB |
Output is correct |
22 |
Correct |
152 ms |
23976 KB |
Output is correct |
23 |
Correct |
158 ms |
26148 KB |
Output is correct |
24 |
Correct |
150 ms |
24008 KB |
Output is correct |
25 |
Correct |
70 ms |
14624 KB |
Output is correct |
26 |
Correct |
66 ms |
14168 KB |
Output is correct |
27 |
Correct |
160 ms |
27292 KB |
Output is correct |
28 |
Correct |
158 ms |
24036 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |