# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240475 | karma | Senior Postmen (BOI14_postmen) | C++14 | 513 ms | 45176 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>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = int(5e5) + 10;
typedef pair<int, int> pii;
struct TEdge {
int u, v;
bool del;
} e[N];
int n, m, vis[N], ss[N], st[N], cnts, cntt;
int path[N], cp;
vector<int> adj[N];
void euler() {
path[++cp] = 1;
int u, i;
do {
u = path[cp];
while(adj[u].size() && e[adj[u].back()].del) adj[u].pop_back();
if(adj[u].size()) {
i = adj[u].back();
adj[u].pop_back();
e[i].del = 1;
path[++cp] = e[i].u ^ e[i].v ^ u;
} else {
st[++cntt] = u;
--cp;
}
} while(cp > 0);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= m; ++i) {
cin >> e[i].u >> e[i].v;
adj[e[i].u].pb(i);
adj[e[i].v].pb(i);
}
euler();
for(int i = 1; i <= cntt; ++i) {
if(vis[st[i]]) {
while(1) {
vis[ss[cnts]] = 0;
cout << ss[cnts] << ' ';
if(ss[cnts --] == st[i]) break;
}
cout << '\n';
}
vis[st[i]] = 1;
ss[++cnts] = st[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... |