# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
993995 | NoLove | Senior Postmen (BOI14_postmen) | C++14 | 8 ms | 27680 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.
/**
* author : Lăng Trọng Đạt
* created: 07-06-2024
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 5;
int g[MAXN], deg[MAXN];
vector<pii> adj[MAXN];
int n, m, a, b;
vector<vi> ans;
bool in_q[MAXN], use[MAXN];
vi path, tour;
void dfs(int v) {
if (in_q[v]) {
ans.pb({v});
in_q[v] = false;
while (path.back() != v) {
ans.back().pb({path.back()});
in_q[path.back()] = 0;
path.pop_back();
}
} else
path.pb(v);
db(v, path)
in_q[v] = 1;
while (si(adj[v])) {
auto[u, id] = adj[v].back();
adj[v].pop_back();
db(v, u, id)
if (use[id]) continue;
use[id] = true;
dfs(u);
}
tour.pb(v);
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("hi.inp", "r")) {
freopen("hi.inp", "r", stdin);
// freopen("hi.out", "w", stdout);
}
cin >> n >> m;
FOR(i, 1, m) {
cin >> a >> b;
adj[a].pb({b, i});
adj[b].pb({a, i});
deg[a]++, deg[b]++;
}
dfs(1);
for (auto v : ans) {
for (int i : v) {
cout << i << " ";
}
cout << "\n";
}
db(tour)
}
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... |