# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119658 | vjudge1 | Senior Postmen (BOI14_postmen) | C++17 | 469 ms | 67688 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 int long long
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >
#define fi first
#define se second
#define task "senior_postmen"
using namespace std;
const int N = 5e5 + 5;
const int mod = 998244353;
int n, m;
vector< ii > g[N];
bool used_edge[N];
bool vis[N], del[N];
list<int> euler_walk(int u) {
list<int> ans;
ans.push_back(u);
while (!g[u].empty()) {
int v = g[u].back().fi;
int eid = g[u].back().se;
g[u].pop_back();
if (used_edge[eid]) continue;
used_edge[eid] = true;
u = v;
ans.push_back(u);
}
for (auto it = ++ans.begin(); it != ans.end(); ++it) {
auto t = euler_walk(*it);
t.pop_back();
ans.splice(it, t);
}
return ans;
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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++)
{
int u, v; cin >> u >> v;
g[u].push_back(ii(v, i));
g[v].push_back(ii(u, i));
}
list < int > ct_euler = euler_walk(1);
// for(auto x : ct_euler) cout << x << " "; cout << endl;
stack < int > st;
for(auto x : ct_euler){
if(vis[x]){
while(!st.empty()){
int v = st.top();
cout << v << " ";
vis[v] = 0;
st.pop();
if(v == x) break;
}
cout << '\n';
}
st.push(x);
vis[x] = 1;
}
}
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... |