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 endl "\n"
#define ll long long
int n, m;
vector<vector<pair<int, int>>> a;
bool kt[500005];
void get_ans(int u)
{
vector<int> ans;
ans.push_back(u);
while (a[u].size())
{
auto [v, id] = a[u].back();
a[u].pop_back();
if (kt[id] == true)
continue;
kt[id] = true;
ans.push_back(v);
u = v;
}
ans.pop_back();
for (int i : ans)
{
cout << i << " ";
}
if (ans.size())
cout << endl;
for (int i : ans)
{
get_ans(i);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
a.assign(n + 1, {});
for (int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
a[u].push_back({v, i});
a[v].push_back({u, i});
}
get_ans(1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |