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;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<long long , long long>
#define vi vector<int>
#define vpii vector<pii>
#define SZ(x) ((int)(x.size()))
#define fi first
#define se second
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define dem(x) __builtin_popcount(x)
#define Mask(x) (1LL << (x))
#define BIT(x, i) ((x) >> (i) & 1)
#define ln '\n'
#define io_faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//template <class T>
//inline void read(T& x){
// bool Neg = false;
// char c;
// for (c = getchar(); c < '0' c > '9'; c = getchar())
// if (c == '-') Neg = !Neg;
// x = c - '0';
// for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
// x = x * 10 + c - '0';
// if (Neg) x = -x;
//}
//
//template <class T>
//inline void write(T x)
//{
// if (x < 0)
// {
// putchar('-'); x = -x;
// }
// T p = 1;
// for (T temp = x / 10; temp > 0; temp /= 10) p *= 10;
// for (; p > 0; x %= p, p /= 10) putchar(x / p + '0');
//}
const int INF = 1e9 , mod = 1e9 + 7;
template <class T1, class T2>
inline void mul(T1& x, T2 k){ x = (1LL * x * k) % mod; }
template <class T1 , class T2>
inline T1 pw(T1 x, T2 k){T1 res = 1; for (; k ; k >>= 1){ if (k & 1) mul(res, x); mul(x, x); } return res;}
template <class T>
inline bool minimize(T &x, T y){ if (x > y){x = y; return 1;} return 0; }
template <class T>
inline bool maximize(T &x, T y){ if (x < y){x = y; return 1;} return 0; }
#define PROB "b"
void file(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp","r",stdin);
freopen(PROB".out","w",stdout);
}
}
void sinh_(){
// srand(time(0));
// freopen(PROB".inp" , "w" , stdout);
// int n;
}
typedef long long ll;
const int N = 5e5 + 2;
int n , m;
vpii adj[N];
void readip(){
cin >> n >> m;
REP(i, 1, m){
int u , v; cin >> u >> v;
adj[u].eb(v , i);
adj[v].eb(u , i);
}
}
stack<int> st;
bool vis[N] , used[N];
void dfs(int u){
vis[u] = 1;
st.push(u);
bool ok = 0;
while(!adj[u].empty()){
pii tmp = adj[u].back();
adj[u].pop_back();
if (used[tmp.se]) continue;
used[tmp.se] = 1;
int v = tmp.fi;
if (vis[v]){
while(st.top() != v){
cout << st.top() << ' ';
vis[st.top()] = 0;
st.pop();
}
cout << st.top() << ln;
vis[st.top()] = 0;
st.pop();
}
dfs(v);
ok = 1;
break;
}
if (!ok) st.pop();
}
void solve(){
REP(i, 1, n) while (!adj[i].empty())
dfs(i);
}
int main(){
sinh_();
io_faster
file();
int t = 1;
// cin >> t;
while (t--){
readip();
solve();
}
}
Compilation message (stderr)
postmen.cpp: In function 'void readip()':
postmen.cpp:20:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
20 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
| ^
postmen.cpp:85:5: note: in expansion of macro 'REP'
85 | REP(i, 1, m){
| ^~~
postmen.cpp: In function 'void solve()':
postmen.cpp:20:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
20 | #define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
| ^
postmen.cpp:124:5: note: in expansion of macro 'REP'
124 | REP(i, 1, n) while (!adj[i].empty())
| ^~~
postmen.cpp: In function 'void file()':
postmen.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen(PROB".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen(PROB".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |