Submission #827108

#TimeUsernameProblemLanguageResultExecution timeMemory
827108vnm06Simurgh (IOI17_simurgh)C++14
51 / 100
1022 ms1972 KiB
#include<bits/stdc++.h> #include "simurgh.h" using namespace std; int sg=0; int par[500], db[500]; bool prov[500000]; int ans[500000]; vector<int> added_edges; std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) { int m=u.size(); for(int i=0; i<n; i++) { ///for(int j=0; j<sg; j++) //cout<<added_edges[j]<<" "; //cout<<endl; if(added_edges.size()==n-1) return added_edges; for(int i=0; i<n; i++) { par[i]=i; db[i]=1; } for(int j=0; j<sg; j++) { int v1=u[added_edges[j]], v2=v[added_edges[j]]; while(v1!=par[v1]) v1=par[v1]; while(v2!=par[v2]) v2=par[v2]; if(db[v1]>db[v2]) par[v2]=v1; else if(db[v1]>db[v2]) par[v1]=v2; else { par[v2]=v1; db[v1]++; } } ///for(int i=0; i<n; i++) //cout<<par[i]<<endl; int cmp; for(cmp=0;; cmp++) { if(cmp>n) return added_edges; if(par[cmp]!=cmp) continue; for(int j=0; j<m; j++) { int v1=u[j], v2=v[j]; while(v1!=par[v1]) v1=par[v1]; while(v2!=par[v2]) v2=par[v2]; if(v1==v2 || v1==cmp || v2==cmp) continue; added_edges.push_back(j); if(db[v1]>db[v2]) par[v2]=v1; else if(db[v1]>db[v2]) par[v1]=v2; else { par[v2]=v1; db[v1]++; } } if(added_edges.size()==n-2) break; added_edges.resize(sg); for(int i=0; i<n; i++) { par[i]=i; db[i]=1; } for(int j=0; j<sg; j++) { int v1=u[added_edges[j]], v2=v[added_edges[j]]; while(v1!=par[v1]) v1=par[v1]; while(v2!=par[v2]) v2=par[v2]; if(db[v1]>db[v2]) par[v2]=v1; else if(db[v1]>db[v2]) par[v1]=v2; else { par[v2]=v1; db[v1]++; } } } int mist=1e9, mast=-1; for(int j=0; j<m; j++) ans[j]=-1; for(int j=0; j<m; j++) { if(prov[j]) continue; int v1=u[j], v2=v[j]; while(v1!=par[v1]) v1=par[v1]; while(v2!=par[v2]) v2=par[v2]; if(v1!=cmp && v2!=cmp) continue; if(v1==v2) continue; prov[j]=1; added_edges.push_back(j); ans[j]=count_common_roads(added_edges); if(ans[j]>mast) mast=ans[j]; if(ans[j]<mist) mist=ans[j]; added_edges.resize(added_edges.size()-1); } added_edges.resize(sg); for(int j=0; j<m; j++) { if(ans[j]==mast) { added_edges.push_back(j); sg++; } } } return added_edges; }

Compilation message (stderr)

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:19:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         if(added_edges.size()==n-1) return added_edges;
      |            ~~~~~~~~~~~~~~~~~~^~~~~
simurgh.cpp:63:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |         if(added_edges.size()==n-2) break;
      |            ~~~~~~~~~~~~~~~~~~^~~~~
#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...