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 int long long
#define INF (int)(1e9)
#define f first
#define s second
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
const int N = 5e5 + 69;
set <int> adj[N], c2;
vector <int> c1;
int curr;
int cnt = 0;
void dfs(int u){
c1.push_back(u);
c2.insert(u);
cnt++;
//cout << u << endl;
for (int v : adj[u]){
if (v == curr) {
adj[u].erase(v);
adj[v].erase(u);
break;
}
else if (c2.find(v) == c2.end()){
adj[u].erase(v);
adj[v].erase(u);
dfs(v);
break;
}
}
}
void Solve(){
cin >> n >> m;
for (int i = 1; i <= m; i++){
int u, v; cin >> u >> v;
adj[u].insert(v);
adj[v].insert(u);
}
for (int i = 1; i <= n; i++){
while (adj[i].size()){
c1.clear();
c2.clear();
int u = i;
curr = u;
dfs(u);
for (auto x : c1) cout << x << " ";
cout << "\n";
}
}
}
int32_t 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... |