# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037374 | vjudge1 | Senior Postmen (BOI14_postmen) | C++17 | 1101 ms | 215152 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) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
vector<int> adj[500010];
bool vis[500010];
priority_queue<int> pq[500010];
stack<int> st;
void dfs(int u,int p)
{
// debug(u);
if(vis[u])
{
int prev=u;
while(st.top()!=u)
{
cout<<st.top()<<' ';
pq[prev].push(st.top());
pq[st.top()].push(prev);
prev=st.top();
vis[st.top()]=0;
st.pop();
}
pq[prev].push(st.top());
pq[st.top()].push(prev);
cout<<st.top()<<'\n';
return;
}
st.push(u);
vis[u]=1;
while(!pq[u].empty() && pq[u].top()==adj[u].back())
{
pq[u].pop();
adj[u].pop_back();
}
for(int i=adj[u].size()-1;i>=0;i--)
{
// debug(adj[u][i]);
while(!pq[u].empty() && pq[u].top()==adj[u].back())
{
pq[u].pop();
adj[u].pop_back();
}
if(i<adj[u].size() && adj[u][i]!=p)
{
// debug(adj[u][i]);
// debug(p);
dfs(adj[u][i],u);
while(!pq[u].empty() && pq[u].top()==adj[u].back())
{
pq[u].pop();
adj[u].pop_back();
}
if(st.top()!=u) return;
}
}
st.pop();
vis[u]=0;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n,m;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++)
{
while(!adj[i].empty()) dfs(i,-1);
}
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... |