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];
bool check[500005];
int l[500005], r[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;
if (check[v] == true)
{
vector<int> res;
while (!ans.empty() && ans.back() != v)
{
res.push_back(ans.back());
check[ans.back()] = false;
ans.pop_back();
}
res.push_back(v);
reverse(res.begin(), res.end());
for (int i : res)
{
cout << i << " ";
}
cout << endl;
// ans.pop_back();
u = v;
kt[id] = true;
continue;
}
kt[id] = true;
check[v] = 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;
l[i] = u;
r[i] = 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... |