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];
vector<int> duyet(ll u)
{
k++;
vector<int> ans;
// cout << u;
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();
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});
}
//for(int i = 1; i <= n ; i ++) q.push_back(i);
// while(!q.empty())
// {
// ll u = q.front();
// if(adj[u].size() == 0)
// {
// q.pop_front();
// continue;
// }
// duyet(u);
// }
vector<int> p ;
p = duyet(1);
stack<int> st;
//for(auto u : p) cout << u <<' ';
//cout <<'\n';
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:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | 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... |