| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355298 | Charizard2021 | 슈퍼트리 잇기 (IOI20_supertrees) | C++20 | 0 ms | 0 KiB |
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > adj;
vector<bool> visited;
bool cycle = false;
void dfs(int u, int p){
if(visited[u]){
cycle = true;
return;
}
visited[u] = true;
for(int v : adj[u]){
if(v != p){
dfs(v, u);
}
}
}
int construct(vector<vector<int> > p){
n = p.size();
sizes.resize(n, 1);
parent.resize(n);
adj.resize(n);
visited.resize(n, false);
bool has1 = false;
for(int i = 0; i < n; i++){
parent[i] = i;
for(int j = i + 1; j < n; j++){
if(p[i][j] == 1){
adj[i].push_back(j);
adj[j].push_back(i);
has1 = true;
}
}
}
for(int i = 0; i < n; i++){
if(!visited[i]){
dfs(i, 0);
}
}
if(!cycle){
vector<vector<int> > answer(n, vector<int>(n, 0));
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
answer[i][j] = p[i][j];
}
}
build(answer);
}
else{
return 0;
}
}
