#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int n, m; cin >> n >> m;
vector<vector<pair<int, int>>> adj(n);
for( int i = 0; i < m; i++ ){
int a, b; cin >> a >> b;
a--; b--;
adj[a].push_back({ b, i });
adj[b].push_back({ a, i });
}
vector<int> marc(m), in_tour(n);
stack<int> tour;
function<void(int)> dfs = [&]( int cur ){
while( !adj[cur].empty() ){
auto [viz, id] = adj[cur].back(); adj[cur].pop_back();
if( marc[id] ) continue; marc[id] = true;
dfs( viz );
}
if( in_tour[cur] ){
while( in_tour[cur] ){
cout << tour.top() + 1 << " ";
in_tour[tour.top()] = false;
tour.pop();
}
cout << endl;
}
tour.push(cur);
in_tour[cur] = true;
};
dfs(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... |