# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
764571 | 2023-06-23T15:45:17 Z | alexander707070 | Connecting Supertrees (IOI20_supertrees) | C++14 | 1000 ms | 2008416 KB |
#include<bits/stdc++.h> #include "supertrees.h" #define MAXN 1006 using namespace std; int n,k; vector<int> cycle[MAXN]; vector<int> v[MAXN]; vector< vector<int> > ans; bool li[MAXN]; int dsu[MAXN]; int root(int x){ if(dsu[x]==x)return x; dsu[x]=root(dsu[x]); return dsu[x]; } void add_edge(int x,int y){ if(x==y)return; ans[x][y]=ans[y][x]=1; } void dfs(int x){ li[x]=true; cycle[k].push_back(x); for(int i=0;i<v[x].size();i++){ if(!li[v[x][i]])dfs(v[x][i]); } } int construct(vector< vector<int> > p){ n=p.size(); ans.resize(n); for(int i=0;i<n;i++)ans[i].resize(n); for(int i=0;i<n;i++){ for(int f=i+1;f<n;f++){ if(p[i][f]==2){ v[i].push_back(f); v[f].push_back(i); } } } for(int i=0;i<n;i++){ if(!li[i]){ k++; dfs(i); //for(int f=0;f<cycle[k].size();f++){ // for(int d=f+1;d<cycle[k].size();d++){ // if(p[cycle[k][f]][cycle[k][d]]!=2)return 0; // } // } for(int f=0;f<cycle[k].size();f++){ dsu[cycle[k][f]]=k; add_edge(cycle[k][f],cycle[k][(f+1)%int(cycle[k].size())]); } } } for(int i=0;i<n;i++){ for(int f=i+1;f<n;f++){ if(p[i][f]==1){ if(root(i)!=root(f)){ dsu[root(f)]=root(i); add_edge(i,f); } } } } for(int i=0;i<n;i++){ for(int f=i+1;f<n;f++){ if(p[i][f]==0 and root(i)==root(f))return 0; } } build(ans); return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Execution timed out | 1120 ms | 1573076 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Execution timed out | 1120 ms | 1573076 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1158 ms | 1970700 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1154 ms | 2008416 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Execution timed out | 1120 ms | 1573076 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Execution timed out | 1120 ms | 1573076 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |