이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int a[1005][1005], i, j, f[1005], k, c[1005], d, l, cnt, pr[1005];
vector<int> s;
int construct(std::vector<std::vector<int>> p)
{
int b;
int n = p.size();
std::vector<std::vector<int>> answer;
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
{
if(p[i][j] == 3) return 0;
if(p[i][j] == 2) d = 1;
}
for(i = 0; i < n; i++)
if(!f[i])
{
if(!c[i]) c[i] = ++k;
for(j = 0; j < n; j++)
if(!f[j] && p[i][j] == 1) c[j] = c[i], f[j] = 1;
}
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
{
if(c[i] == c[j] && p[i][j] != 1) return 0;
if(c[i] == c[j] && i != j) a[i][j] = a[j][i] = 1;
}
for(i = 0; i < n; i++)
f[i] = 0;
if(d)
{
for(i = 0; i < n; i++)
if(!f[i])
{
f[i] = 1;
vector<int> e, r;
for(j = 0; j < n; j++)
if(!f[j] && a[i][j]) { f[j] = 1, pr[j] = i; e.pb(j); }
l = i, cnt = 0;
r.pb(i);
for(j = 0; j < n; j++)
if(!f[j] && p[i][j] == 2)
{
r.pb(j);
f[j] = 1, a[l][j] = a[j][l] = 1, l = j;
for(b = 0; b < n; b++)
if(!f[b] && a[j][b]) { f[b] = 1, pr[b] = j; e.pb(b); }
cnt++;
}
if(cnt < 2) return 0;
a[i][l] = a[l][i] = 1;
for(auto x : r)
for(auto y : r)
if(x != y && p[x][y] != 2) return 0;
for(auto x : r)
for(auto y : e)
{
if(x != y && x != pr[y] && p[x][y] != 2) return 0;
if(x != y && x == pr[y] && p[x][y] != 1) return 0;
}
for(auto x : e)
for(auto y : e)
{
if(x != y && p[x] != p[y] && p[x][y] != 2) return 0;
if(x != y && p[x] == p[y] && p[x][y] != 1) return 0;
}
}
}
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
s.push_back(a[i][j]);
answer.push_back(s);
s.clear();
}
build(answer);
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |