Submission #540165

#TimeUsernameProblemLanguageResultExecution timeMemory
540165status_codingConnecting Supertrees (IOI20_supertrees)C++14
100 / 100
191 ms24056 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int n; bool bad=false; vector<vector<int>> ans; int viz[1005], viz2[1005]; void addEdge(int x, int y) { ans[x][y] = ans[y][x] = 1; } void solve(vector<int> &v, vector<vector<int>> &p) { vector<int> circle; for(int i : v) { if(!viz2[i]) { circle.push_back(i); viz2[i]=true; for(int j=0;j<n;j++) if(i != j && p[i][j] == 1) { addEdge(i ,j); viz2[j]=true; for(int k=0;k<n;k++) if(p[i][k] != p[j][k]) bad = true; } } } if((int)circle.size() == 2) bad=true; if(circle.size() > 1) { for(int i=1; i<(int)circle.size(); i++) addEdge(circle[i-1], circle[i]); if(circle.size() > 2) addEdge(circle[0], circle.back()); } } int construct(vector<vector<int>> p) { n=p.size(); ans.resize(n); for(int i=0;i<n;i++) ans[i].resize(n); //cout<<ans.size()<<'\n'; for(int i=0;i<n;i++) for(int it : p[i]) if(it == 3 ) return 0; for(int i=0;i<n;i++) { if(!viz[i]) { vector<int> v; for(int j=0;j<n;j++) if(p[i][j]) { v.push_back(j); viz[j]=true; } for(int it : v) for(int j=0;j<n;j++) if( (p[it][j] && !p[i][j]) || (!p[it][j] && p[i][j]) ) return 0; solve(v, p); } } if(bad) return 0; build(ans); return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...