Submission #1038202

#TimeUsernameProblemLanguageResultExecution timeMemory
1038202vjudge1Senior Postmen (BOI14_postmen)C++17
100 / 100
294 ms125884 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cerr << #x << " => " << x << endl #define all(x) x.begin(),x.end() int n,m; vector<int> adj[500010]; bool vis[500010]; priority_queue<int> pq[500010]; vector<pii> p; void solve() { stack<pii> st; for(auto i : p) { st.push(i); vis[i.fi]=1; if(vis[i.se]) { while(st.top().fi!=i.se) { cout<<st.top().fi<<' '; vis[st.top().fi]=0; st.pop(); } cout<<i.se<<'\n'; vis[i.se]=0; st.pop(); } } exit(0); } void dfs(int u) { if(p.size()==m) solve(); // debug(u); // debug(adj[u].size()); while(!pq[u].empty() && pq[u].top()==adj[u].back()) { pq[u].pop(); adj[u].pop_back(); } while(!adj[u].empty()) { int v=adj[u].back(); pq[u].push(v); pq[v].push(u); p.pb({u,v}); dfs(v); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m; for(int i=0;i<m;i++) { int u,v;cin>>u>>v; adj[u].pb(v); adj[v].pb(u); } for(int i=1;i<=n;i++) sort(all(adj[i])); for(int i=1;i<=n;i++) dfs(i); // for(auto i : p) cerr<<i.fi<<" "<<i.se<<'\n'; return 0; }

Compilation message (stderr)

postmen.cpp: In function 'void dfs(int)':
postmen.cpp:46:13: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |  if(p.size()==m) solve();
      |     ~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...