# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1018884 | Mardonbekhazratov | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <vector>
using namespace std;
int n;
bool ok;
vector<int>in;
vector<vector<int>>v,comp;
vector<bool>vis;
void dfs(int x){
comp[in[x]].push_back(x);
vis[x]=true;
for(int i=x+1;i<n;i++){
if(v[x][i]){
if(vis[i]){
ok=false;
return;
}
in[i]=in[x];
dfs(i);
}
}
}
int construct(vector<vector<int>> p) {
swap(p,v);
n=v.size();
in.resize(n);
vis.assign(n,false);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(v[i][j]!=v[j][i]) return 0;
}
}
ok=true;
for(int i=0;i<n;i++){
if(!vis[i]){
in[i]=comp.size();
comp.push_back({});
dfs(i);
}
}
if(!ok) return 0;
vector<vector<int>>ans(n,vector<int>(n,0));
for(auto g:comp){
for(int i=1;i<g.size();i++){
ans[g[i]][g[i-1]]=ans[g[i-1]][g[i]]=1;
for(int j=0;j<i;j++){
if(v[i][j]==0) return 0;
}
}
}
build(ans);
return 1;
}
Compilation message (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... |