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>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using vpl = vector<pl>;
#define mp make_pair
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin() , (x).end()
ld dist(ld x, ld y, ld a, ld b) { return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
ll gcd(ll a , ll b){ return b ? gcd(b , a % b) : a ;}
ll lcm(ll a , ll b){ return (a * b) / gcd(a , b);}
ll fact(ll n) { return n > 1?(n * fact(n-1)):1;}
const int MOD = 1000*1000*1000+7;
const long double EPS = 0.000000001;
const double PI = 3.14159265358979323846;
const long long INF = 1e18;
const int nx[4] = {0, 0, -1, 1}, ny[4] = {1, -1, 0, 0};
int n, m; vector<ii>adj[500024];
bool queued[500024], vis[500024]; int cnt[500024];
int dfs(int v, int p=-1)
{
if(queued[v]) {
cout<<v+1<<" ";
return v;
}
queued[v]=1;
for(;cnt[v]<adj[v].size();cnt[v]++) {
ii u=adj[v][cnt[v]];
if(u.ff==p||vis[u.ss]) continue;
vis[u.ss]=true; int next=dfs(u.ff, v);
if(next!=v) {
queued[v]=0;
cout<<v+1<<" ";
return next;
}
cout<<"\n";
}
return -1;
}
int32_t main()
{
ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int l=0;l<m;l++) {
int a, b; cin>>a>>b; a--; b--;
adj[a].pb({b, l}); adj[b].pb({a, l});
}
for(int l=0;l<n;l++) dfs(l);
return 0;
}
Compilation message (stderr)
postmen.cpp: In function 'int dfs(int, int)':
postmen.cpp:44:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(;cnt[v]<adj[v].size();cnt[v]++) {
| ~~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |