# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
930674 | Cutebol | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 168 ms | 24232 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1003 ;
const int inf = 1e9 ;
int pr[N] , sz[N] , vis[N] ;
vector <int> vec[N] ;
int find ( int a ){
if ( a == pr[a] ) return a ;
return pr[a] = find(pr[a]) ;
}
void merge ( int a , int b ){
a = find(a) ;
b = find(b) ;
if ( a != b ){
if ( sz[a] > sz[b] ) swap(a,b) ;
sz[b] += sz[a] ;
pr[a] = b ;
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
for ( int i = 0 ; i < n ; i ++ ) pr[i] = i , sz[i] = 1 ;
for ( int i = 0 ; i < n ; i ++ ){
for ( int j = 0 ; j < n ; j ++ ){
if ( p[i][j] && i != j ){
if ( p[i][j] == 3 ) return 0 ;
merge(i,j) ;
}
}
}
for ( int i = 0 ; i < n ; i ++ ){
for ( int j = 0 ; j < n ; j ++ ){
if ( p[i][j] == 0 && find(i) == find(j) ) return 0 ;
}
}
for ( int i = 0 ; i < n ; i ++ ) vec[find(i)].push_back(i) ;
for ( int i = 0 ; i < n ; i ++ ) pr[i] = i , sz[i] = 1 ;
for ( vector <int> v : vec ){
for ( auto i : v ){
for ( auto j : v ){
if ( p[i][j] == 1 ) merge(i,j) ;
}
}
for ( auto i : v ){
for ( auto j : v ){
if ( p[i][j] == 2 && find(i) == find(j) ) return 0 ;
}
}
vector <int> b ;
for ( auto i : v ){
if ( find(i) != i ){
answer[i][find(i)] = 1 ;
answer[find(i)][i] = 1 ;
}
if ( !vis[find(i)] ){
vis[find(i)] = 1 ;
b.push_back(find(i)) ;
}
}
if ( b.size() == 2 && p[b[0]][b[1]] == 2 ) return 0 ;
for ( int i = 1 ; i < b.size() ; i ++ ){
answer[b[i]][b[i-1]] = 1 ;
answer[b[i-1]][b[i]] = 1 ;
}
if ( b.size() > 1 ){
answer[b[0]][b[b.size()-1]] = 1 ;
answer[b[b.size()-1]][b[0]] = 1 ;
}
}
build(answer);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |