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>
#define endl '\n'
#define mod 1000000007
using namespace std;
void DFS(vector<pair<int,int>> adjList[], int u, vector<int> °ree, vector<bool> &edge, vector<int> &cycle) {
degree[u]-=2;
for (auto x : adjList[u]) {
int v = x.first, pos = x.second;
if (degree[v] && !edge[pos]) {
edge[pos] = true;
DFS(adjList,v,degree,edge,cycle);
}
}
cycle.push_back(u);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n, m; cin >> n >> m;
vector<pair<int,int>> adjList[n];
vector<int> degree(n,0);
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
adjList[u-1].push_back({v-1,i});
adjList[v-1].push_back({u-1,i});
degree[u-1]++; degree[v-1]++;
}
vector<bool> edge(m,false);
for (int i = 0; i < n; i++) {
vector<int> cycle;
if (degree[i]) DFS(adjList,i,degree,edge,cycle);
reverse(cycle.begin(),cycle.end());
for (int vl : cycle) cout << vl+1 << " ";
cout << endl;
}
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... |