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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 1e9
using namespace std;
typedef long long ll;
vector<pair<int,int>>adj[500005];
bool visited[500005];
vector<int>path;
int seen[500005];
void dfs(int s) {
while (adj[s].size()) {
int u = adj[s].back().first; int idx = adj[s].back().second;
adj[s].pop_back();
if (visited[idx])continue;
visited[idx] = true;
dfs(u);
}
path.push_back(s);
seen[s]++;
if (seen[s] == 2) {
cout << s << " ";
path.pop_back();
while (path.back() != s) {
cout << path.back() << " ";
seen[path.back()]--;
path.pop_back();
}
cout << "\n";
seen[s]--;
}
}
void solve()
{
int n, m; cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y; cin >> x >> y;
adj[x].push_back({ y, i });
adj[y].push_back({ x, i });
}
dfs(1);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;// cin>>t;
while (t--) solve();
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... |