Submission #650803

#TimeUsernameProblemLanguageResultExecution timeMemory
650803groshiSenior Postmen (BOI14_postmen)C++17
100 / 100
400 ms83452 KiB
#include<iostream> #include<vector> #include<utility> #include<unordered_map> #include<set> using namespace std; int byla[1000000]; int odw[1000000]; set<pair<int,int> > secik; struct wi{ vector<pair<int,int> > Q; int odw=0; int wyszlam=0; }*w; vector<int> stos,wynik; int kiedy=1; int wzielam=0; int dokad=0; bool czy[1000000]; void dfs(int x,int ojc) { //cout<<x<<" "<<ojc<<"\n"; stos.push_back(x); w[x].odw=kiedy; for(int i=0;i<w[x].Q.size();i++) { //cout<<"zdycham\n"; int pom=w[x].Q[i].first; int ktora=w[x].Q[i].second; while(czy[ktora]==1) { swap(w[x].Q[i],w[x].Q.back()); w[x].Q.pop_back(); if(i>=w[x].Q.size()) break; pom=w[x].Q[i].first; ktora=w[x].Q[i].second; } //cout<<"zdycham 2\n"; if(i>=w[x].Q.size()) break; if(pom==ojc) continue; if(w[pom].odw==kiedy && w[pom].wyszlam==kiedy) continue; if(w[pom].odw!=kiedy) { dfs(pom,x); if(dokad==0) continue; czy[ktora]=1; cout<<stos.back()<<" "; if(dokad!=x) stos.pop_back(); if(dokad==x) { cout<<"\n"; dokad=0; //cout<<"tako\n"; continue; } w[x].wyszlam=kiedy; //cout<<"wychodze z "<<x<<"\n"; return; } //cout<<"bede chciec znalezc cykl od "<<x<<" do "<<pom<<"\n"; czy[ktora]=1; cout<<stos.back()<<" "; dokad=pom; stos.pop_back(); w[x].wyszlam=kiedy; //cout<<"umieram\n"; return; } w[x].wyszlam=kiedy; stos.pop_back(); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,x,y; cin>>n>>m; w=new wi[n+3]; for(int i=0;i<m;i++) { cin>>x>>y; w[x].Q.push_back({y,i}); w[y].Q.push_back({x,i}); } for(int i=1;i<=n;i++) { kiedy++; dfs(i,0); } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'void dfs(int, int)':
postmen.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<w[x].Q.size();i++)
      |                 ~^~~~~~~~~~~~~~
postmen.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             if(i>=w[x].Q.size())
      |                ~^~~~~~~~~~~~~~~
postmen.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(i>=w[x].Q.size())
      |            ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...