#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int INF = 1e9;
const int MAXN = (int) 5e5;
vector < pair <int, int> > g[MAXN + 1];
int edge[MAXN + 1], now;
int in_stk[MAXN + 1];
stack < pair <int, int> > stk;
void dfs(int nod, int par, int id) {
stk.push({nod, id});
in_stk[nod]++;
for(auto it : g[nod]) {
if(it.first == par) {
continue;
}
if(edge[it.second] < now) {
edge[it.second] = now;
if(in_stk[it.first] == 0) {
dfs(it.first, nod, it.second);
}
else {
edge[it.second] = INF;
while(stk.top().first != it.first) {
cout << stk.top().first << " ";
in_stk[stk.top().first]--;
edge[stk.top().second] = INF;
stk.pop();
}
cout << it.first << "\n";
}
}
}
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for(i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
g[x].push_back({y, i});
g[y].push_back({x, i});
}
for(i = 1; i <= n; i++) {
while(!stk.empty()) {
in_stk[stk.top().first] = 0;
stk.pop();
}
now++;
dfs(i, 0, 0);
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12032 KB |
Output is correct |
2 |
Incorrect |
11 ms |
12160 KB |
Edge does not exist or used 2, 7 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12032 KB |
Output is correct |
2 |
Incorrect |
11 ms |
12032 KB |
Edge does not exist or used 2, 7 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12160 KB |
Output is correct |
2 |
Incorrect |
17 ms |
12032 KB |
Edge does not exist or used 2, 7 |
3 |
Halted |
0 ms |
0 KB |
- |