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 vis[mxN];
bool used[mxM];
vector<int> cyc;
void dfs(int u) {
if (vis[u]) {
int v;
do {
v = cyc.back();
cout << v << ' ';
cyc.pop_back();
vis[v] = 0;
} while (v != u);
cout << '\n';
}
cyc.push_back(u);
vis[u] = 1;
for (ii& e : al[u]) if (!used[e.second]) {
used[e.second] = 1;
dfs(e.first);
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){
dfs(i);
while (SZ(cyc)) {
vis[cyc.back()] = 0;
cyc.pop_back();
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |