# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1038202 | vjudge1 | Senior Postmen (BOI14_postmen) | C++17 | 294 ms | 125884 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |