Submission #985746

#TimeUsernameProblemLanguageResultExecution timeMemory
985746user736482Connecting Supertrees (IOI20_supertrees)C++17
96 / 100
163 ms24604 KiB
#include<bits/stdc++.h> #include "supertrees.h" using namespace std; vector<pair<int,int>>edges; int n; int construct(vector<vector<int>> p){ n=(int)p.size(); vector<vector<int>>odp; for(int i=0;i<n;i++){ vector<int>v; for(int j=0;j<n;j++){ v.push_back(0); } odp.push_back(v); } bool ifdeleted[n]; for(int i=0;i<n;i++){ ifdeleted[i]=0; } for(int i=0;i<n;i++){ if(ifdeleted[i]) continue; vector<int>same; for(int j=0;j<n;j++){ if(p[i][j]==1){ if(p[i]==p[j]) same.push_back(j); else return 0; } } for(int j=1;j<(int)same.size();j++){ edges.push_back({same[j-1],same[j]}); ifdeleted[same[j]]=1; for(int k=0;k<n;k++){ p[k][same[j]]=-1; } } } for(int i=0;i<n;i++){ if(p[i][i]!=-1) p[i][i]=2; } for(int i=0;i<n;i++){ if(ifdeleted[i]) continue; vector<int>same; for(int j=0;j<n;j++){ if(p[i][j]==2){ if(p[i]==p[j]) same.push_back(j); else return 0; } } //same.push_back(i); if(same.size()==2) return 0; if(same.size()>2) edges.push_back({same[0],same[(int)same.size()-1]}); for(int j=1;j<(int)same.size();j++){ edges.push_back({same[j-1],same[j]}); ifdeleted[same[j]]=1; for(int k=0;k<n;k++){ p[k][same[j]]=-1; } } } for(int i=0;i<(int)edges.size();i++){ //cout<<edges[i].first<<" "<<edges[i].second<<"\n"; odp[edges[i].first][edges[i].second]=1; odp[edges[i].second][edges[i].first]=1; } build(odp); return 1; } /*int main(){ construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}}); return 0; }*/
#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...