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 TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
typedef pair<int,int> ii;
const int mxN = 5e5+5;
const int mxM = 5e5+5;
int N, M;
vector<ii> al[mxN];
bool used[mxM];
vector<int> cyc;
void dfs(int u, int r) {
cyc.push_back(u);
for (ii& e : al[u]) if (!used[e.second]) {
used[e.second] = 1;
if (e.first != r) dfs(e.first, r);
return;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> M;
FOR(i,1,M){
int U, V; cin >> U >> V;
al[U].push_back(ii(V,i));
al[V].push_back(ii(U,i));
}
FOR(i,1,N){
cyc.clear();
dfs(i,i);
if (SZ(cyc) > 1) {
for (int& v : cyc) {
cout << v << ' ';
}
cout << '\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |