# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
832737 | serifefedartar | Senior Postmen (BOI14_postmen) | C++17 | 441 ms | 80052 KiB |
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 fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 300005
vector<vector<pair<int,int>>> graph;
vector<bool> active;
vector<int> pathVis;
int go_back = 0;
void dfs(int node, int parent) {
pathVis[node] = true;
for (auto u : graph[node]) {
if (u.f == parent || !active[u.s])
continue;
if (pathVis[u.f]) {
printf("%d ", u.f);
go_back = u.f;
active[u.s] = false;
} else
dfs(u.f, node);
if (go_back) {
if (go_back == node) {
go_back = 0;
active[u.s] = false;
printf("\n");
continue ;
}
printf("%d ", node);
active[u.s] = false;
pathVis[node] = false;
return ;
}
}
pathVis[node] = false;
}
int main() {
int N, M, a, b;
scanf("%d %d", &N, &M);
graph = vector<vector<pair<int,int>>>(N+1, vector<pair<int,int>>());
active = vector<bool>(M, true);
pathVis = vector<int>(N+1, false);
for (int i = 0; i < M; i++) {
scanf("%d %d", &a, &b);
graph[a].push_back({b, i});
graph[b].push_back({a, i});
}
for (int i = 1; i <= N; i++)
dfs(i, i);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |