#include "supertrees.h"
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
using vb=vector<bool>;
using vi=vector<int>;
using vvi=vector<vi>;
const int mxN=1e3+1;
int n;
vb vis;
vvi ans;
struct DSU {
int par[mxN], sz[mxN];
DSU() {
for (int i=0; i<n; ++i)
par[i]=i, sz[i]=1;
}
int find(int v) {
return (par[v]==v?v:par[v]=find(par[v]));
}
bool merge(int a, int b) {
a=find(a), b=find(b);
if (a==b)
return 0;
if (sz[a]>sz[b])
swap(a, b);
par[a]=b, sz[b]+=sz[a];
return 1;
}
bool same(int a, int b) {
return (find(a)==find(b));
}
};
int construct(vvi p) {
n=p.size();
ans=vvi(n, vi(n));
DSU d[3];
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j) {
if (p[i][j]==1)
d[p[i][j]].merge(i, j);
else 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]==2)
d[2].merge(d[1].find(i), d[1].find(j));
else if (!p[i][j]) {
for (int k=1; k<4; ++k)
if (d[k].same(i, j))
return 0;
}
}
vis=vb(n);
for (int i=0; i<n; ++i) {
if (vis[d[1].find(i)])
continue;
vis[d[1].find(i)]=1;
for (int j=0; j<n; ++j)
if (i^j && d[1].same(i, j)) {
if (p[i]!=p[j])
return 0;
ans[i][j]=ans[j][i]=1;
}
}
vis=vb(n);
for (int i=0; i<n; ++i) {
if (vis[d[2].find(i)])
continue;
vis[d[2].find(i)]=1;
vi v;
for (int j=0; j<n; ++j)
if (d[2].same(i, j))
v.eb(j);
int sz=v.size();
if (sz==1)
continue;
if (sz==2)
return 0;
for (int j=0; j<sz; ++j) {
if (j)
ans[v[j]][v[j-1]]=ans[v[j-1]][v[j]]=1;
if (j<sz-1)
ans[v[j]][v[j+1]]=ans[v[j+1]][v[j]]=1;
}
ans[v[0]][v.back()]=ans[v.back()][v[0]]=1;
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
247 ms |
24044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
247 ms |
24044 KB |
Output is correct |
8 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
247 ms |
24044 KB |
Output is correct |
8 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
247 ms |
24044 KB |
Output is correct |
8 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 7 (could be triggered by violating memory limits) |
9 |
Halted |
0 ms |
0 KB |
- |