Submission #540152

#TimeUsernameProblemLanguageResultExecution timeMemory
540152status_codingConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1 ms212 KiB
#include "supertrees.h" #include <bits/stdc++.h> using namespace std; int n; 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; } } } 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]) { if(i) exit(1); vector<int> v; for(int j=0;j<n;j++) if(p[i][j]) { v.push_back(j); viz[j]=true; } solve(v, p); } } 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...