# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941126 | Sir_Ahmed_Imran | Senior Postmen (BOI14_postmen) | C++17 | 377 ms | 90596 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.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define N 500001
int st;
int vis[N];
int evis[N];
vector<int> x;
vector<pii> a[N];
void dfs(int v){
int u;
vis[v]=1;
x.append(v);
while(!a[v].empty()){
while(!a[v].empty() && evis[a[v].back().ss])
a[v].pop_back();
if(a[v].empty()){
x.pop_back();
return;
}
u=a[v].back().ff;
evis[a[v].back().ss]=1;
if(vis[u]){
cout<<u<<' ';
while(x.back()!=u){
cout<<x.back()<<' ';
vis[x.back()]=0;
x.pop_back();
}
cout<<nl;
st=u;
}
else dfs(u);
if(v!=st) return;
}
}
void solve(){
int n,m,o,p,q,r;
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>p>>q;
a[p].append({q,i});
a[q].append({p,i});
}
for(int i=1;i<=n;i++)
dfs(i);
}
int main(){
L0TA;
solve();
return 0;
}
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... |