| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1041891 | MarwenElarbi | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 119 ms | 27180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define pb push_back
const int nax=1005;
vector<int> adj[nax];
vector<int> comp[nax];
int parent[nax];
int find(int x){
if(x==parent[x]) return x;
return parent[x]=find(parent[x]);
}
bool sameset(int x,int y){
return find(x)==find(y);
}
void joinset(int x,int y){
x=find(x);
y=find(y);
if(comp[y].size()<comp[x].size()) swap(comp[x],comp[y]);
for(auto u:comp[x]) comp[y].pb(u);
parent[x]=y;
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> ans(n,vector<int> (n,0));
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(i==j) continue;
if(p[i][j]>0) adj[i].pb(j);
}
}
for (int i = 0; i < n; ++i)
{
parent[i]=i;
}
for (int i = 0; i < n; ++i)
{
for(auto u:adj[i])
if(!sameset(u,i)) joinset(u,i);
}
bool test=true;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(i==j) continue;
if(p[i][j]==0&&sameset(i,j)) test=false;
}
}
if(!test) return test;
for (int i = 0; i < n; ++i)
{
parent[i]=i;
adj[i].clear();
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(i==j) continue;
if(p[i][j]==1&&!sameset(j,i)){
adj[i].pb(j);
adj[j].pb(i);
joinset(j,i);
}
}
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(i==j) continue;
if(p[i][j]==2&&sameset(i,j)) test=false;
}
}
if(!test) return test;
for (int i = 0; i < n; ++i)
{
if(comp[find(i)].empty()) comp[find(i)].pb(find(i));
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if(i==j) continue;
if(p[i][j]==2&&!sameset(i,j)){
joinset(i,j);
}
}
}
bool vis[n];
memset(vis,0,sizeof vis);
for (int i = 0; i < n; ++i)
{
if(!vis[find(i)]){
int x=find(i);
vis[x]=true;
if(comp[x].size()==1) continue;
if(comp[x].size()==2){
test=false;
break;
}
for (int j = 0; j < comp[x].size(); ++j)
{
adj[comp[x][j]].pb(comp[x][(j+1)%(int)comp[x].size()]);
adj[comp[x][(j+1)%(int)comp[x].size()]].pb(comp[x][j]);
}
}
}
if(!test) return 0;
for (int i = 0; i < n; ++i)
{
for(auto u:adj[i]) ans[i][u]=1;
}
build(ans);
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... | ||||
