Submission #755470

#TimeUsernameProblemLanguageResultExecution timeMemory
755470irmuunSenior Postmen (BOI14_postmen)C++17
55 / 100
511 ms108384 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define all(s) s.begin(),s.end() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; set<int>adj[n+1]; vector<int>used(n+1,0); for(int i=1;i<=m;i++){ int u,v; cin>>u>>v; adj[u].insert(v); adj[v].insert(u); } vector<int>ord; function <void(int)> dfs=[&](int x){ ord.pb(x); if(adj[x].size()==0){ return; } int y=*adj[x].begin(); adj[x].erase(y); adj[y].erase(x); dfs(y); }; for(int i=1;i<=n;i++){ if(adj[i].size()>0){ dfs(i); } } vector<int>v; for(int i=0;i<ord.size();i++){ if(used[ord[i]]==0){ used[ord[i]]=1; v.pb(ord[i]); } else{ int x=ord[i]; cout<<x<<' '; while(!v.empty()){ int y=v.back(); if(x!=y){ cout<<y<<' '; v.pop_back(); used[y]=0; } else{ break; } } cout<<"\n"; } } }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<ord.size();i++){
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...