# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119669 | vjudge1 | Senior Postmen (BOI14_postmen) | C++17 | 520 ms | 70712 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 ii pair<int,int>
#define fi first
#define se second
#define int long long
#define task ""
using namespace std;
const int N = 5e5 + 10, mod = 1e9 + 7;
const int oo = 1e18;
int n, m;
struct edge{
int v, id;
};
vector<edge> g[N];
bool used_edge[N], vst[N];
stack<int> st;
list<int> euler_walk(int u){
list<int> ans;
ans.push_back(u);
while(!g[u].empty()){
int v = g[u].back().v;
int id = g[u].back().id;
g[u].pop_back();
if(used_edge[id]) continue;
used_edge[id] = 1;
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({v, i});
g[v].push_back({u, i});
}
list<int> ans = euler_walk(1);
vector<int> v;
for(int x : ans) v.push_back(x);
// v.pop_back();
// for(int i = 0; i < v.size(); i++)
// cout << v[i] << ' ';
// cout << '\n';
for(int i = 0; i < v.size(); i++){
// cout << v[i] << ' ';
if(vst[v[i]]){
int x = st.top();
cout << v[i] << ' ';
while(x != v[i]){
cout << x << ' ';
vst[x] = 0;
st.pop();
x = st.top();
}
st.pop();
cout << '\n';
}
st.push(v[i]);
vst[v[i]] = 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... |