#include <bits/stdc++.h>
using namespace std;
void setup()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int n, m, a, b;
bool check[500000];
vector<pair<int, int>> g[500000];
vector<int> v, e;
inline void DFS(int node)
{
bool found = false;
while (!g[node].empty())
{
if (!check[g[node].back().second])
{
found = true;
v.push_back(g[node].back().second);
check[g[node].back().second] = true;
a = g[node].back().first;
g[node].pop_back();
DFS(a);
e.push_back(v.back());
v.pop_back();
}
else
{
g[node].pop_back();
}
}
}
int main()
{
setup();
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
cin >> a >> b;
g[a - 1].push_back({b - 1, i});
g[b - 1].push_back({a - 1, i});
}
DFS(0);
for (auto & i : e)
{
cout << i + 1 << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |