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>
#define ll long long
using namespace std;
const ll N = 1e6 + 5;
ll vi[N] , n , m ,k, ok[N];
deque<int> q;
vector<pair<int, int>> adj[N];
list <int> duyet(ll u)
{
list<int> ans;
ans.push_back(u);
while(!adj[u].empty())
{
int v = adj[u].back().first;
int id = adj[u].back().second;
adj[u].pop_back();
if(vi[id]) continue;
vi[id] = 1;
u = v;
ans.push_back(u);
}
for (auto it = ++ans.begin(); it != ans.end(); ++it) {
auto t = duyet(*it);
t.pop_back();
ans.splice(it, t);
//for(auto uu : t) ans.push_back(uu);
}
return ans;
}
main()
{
cin >> n >> m;
for(int i = 1; i <= m ; i ++)
{
ll x, y;
cin >> x >> y;
adj[x].push_back({y, i});
adj[y].push_back({x, i});
}
list <int> p ;
p = duyet(1);
stack<int> st;
for(auto u : p)
{
st.push(u);
ok[u]++;
if(ok[st.top()] > 1)
{
while(!st.empty())
{
ll v = st.top();
if(ok[v] == 1 && v == u) break;
ok[v]--;
cout << v <<' ';
st.pop();
}
cout <<'\n';
}
}
}
Compilation message (stderr)
postmen.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |