# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941132 | Faisal_Saqib | Senior Postmen (BOI14_postmen) | C++17 | 1037 ms | 28496 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 F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 5e5 + 10;
bool mark[N], see[N];
vector<int> adj[N];
pii e[N];
vector<int> tour, st;
void dfs(int v){
for(auto i : adj[v]){
if(mark[i])continue;
int u = e[i].F + e[i].S - v;
mark[i] = true;
dfs(u);
}
tour.pb(v);
}
int main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n, m; scanf("%d %d", &n ,&m);
for(int i=0; i<m; i++){
int u, v; scanf("%d %d", &u, &v);
adj[u].pb(i);
adj[v].pb(i);
e[i] = {u, v};
}
dfs(1);
for(auto u : tour){
if(!see[u]){
see[u] = true;
st.pb(u);
}else{
while(st.back() != u){
printf("%d ", st.back());
see[st.back()] = false;
st.pop_back();
}
printf("%d\n", u);
}
}
}
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... |