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 <iostream>
#include <vector>
#define pii pair<int, int>
#define fst first
#define snd second
using namespace std;
const int INF = 1e9;
int N, M, H[500001];
vector<pii> adj[500001];
bool used[500001];
int DFS(int u)
{
while (adj[u].size())
{
int v = adj[u].back().fst, id = adj[u].back().snd; adj[u].pop_back();
if (used[id]) continue;
used[id] = 1;
if (H[v] < H[u])
{
cout << u + 1 << " ";
H[u] = INF;
return H[v];
}
H[v] = H[u] + 1;
int ret = DFS(v);
if (ret < H[u])
{
cout << u + 1 << " ";
H[u] = INF;
return ret;
}
if (ret == H[u]) {cout << u + 1 << "\n";}
}
H[u] = INF;
return INF;
}
int main()
{
cin.tie(0) -> sync_with_stdio(0);
cin >> N >> M;
for (int i = 0; i < N; i++) H[i] = INF;
for (int i = 0; i < M; i++)
{
int u, v; cin >> u >> v;
adj[u - 1].push_back({v - 1, i});
adj[v - 1].push_back({u - 1, i});
}
for (int i = 0; i < N; i++)
{
if (adj[i].size()) {H[i] = 0; DFS(i);}
}
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... |