이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include<bits/stdc++.h>
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
const int MAX = 10002;
int link[MAX];
inline int seek(int x){
if(x == link[x]) return x;
return link[x] = seek(link[x]);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for(int i = 0; i < n; i++) link[i] = i;
int f = 0;
bool flag = 1;
for(auto i: p){
int a = seek(f);
for(int j = 0; j < n; j++){
if(f!=j and i[j] == 1) flag = 0;
if(i[j] != 0){
int b = seek(j);
link[b] = a;
}
}
f++;
}
vector<int> cc[MAX];
for(int i = 0; i < n; i++){
cc[ link[i] ].push_back(i);
}
int mat[n+1][n+1];
memset(mat,0,sizeof(mat));
for(int i = 0; i < n; i++){
int sz = (int)(cc[i].size());
for(int j = 0; j < sz-1; j++){
mat[ cc[i][j] ][ cc[i][j+1] ] = 1;
mat[ cc[i][j+1] ][ cc[i][j] ] = 1;
}
if(flag and sz > 1){
mat[ cc[i][0] ][ cc[i][ sz-1 ] ] = 1;
mat[ cc[i][ sz-1 ] ][ cc[i][0] ] = 1;
}
}
for(int i = 0; i < n; i++){
vector<int> asd;
for(int j = 0; j < n; j++){
asd.push_back(mat[i][j]);
}
answer.push_back(asd);
}
bool ok = 1;
f = 0;
for(auto i: p){
for(int j = 0; j < n; j++){
if(i[j] == 0 and link[f] == link[j]){
ok = 0;
break;
}
}
f++;
if(!ok) break;
}
if(ok){
build(answer);
return 1;
}
else return 0;
}
# | 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... |