#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
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
8 ms |
11988 KB |
Output is correct |
3 |
Correct |
8 ms |
11988 KB |
Output is correct |
4 |
Correct |
8 ms |
12116 KB |
Output is correct |
5 |
Correct |
7 ms |
12116 KB |
Output is correct |
6 |
Correct |
7 ms |
12208 KB |
Output is correct |
7 |
Correct |
10 ms |
12628 KB |
Output is correct |
8 |
Correct |
7 ms |
12216 KB |
Output is correct |
9 |
Correct |
35 ms |
15332 KB |
Output is correct |
10 |
Correct |
8 ms |
12116 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
37 ms |
15736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
12116 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Correct |
10 ms |
12212 KB |
Output is correct |
7 |
Correct |
10 ms |
12700 KB |
Output is correct |
8 |
Correct |
7 ms |
12116 KB |
Output is correct |
9 |
Correct |
29 ms |
15220 KB |
Output is correct |
10 |
Correct |
8 ms |
12112 KB |
Output is correct |
11 |
Correct |
8 ms |
12116 KB |
Output is correct |
12 |
Correct |
46 ms |
15744 KB |
Output is correct |
13 |
Correct |
46 ms |
17456 KB |
Output is correct |
14 |
Correct |
46 ms |
16716 KB |
Output is correct |
15 |
Correct |
45 ms |
16176 KB |
Output is correct |
16 |
Correct |
45 ms |
17484 KB |
Output is correct |
17 |
Correct |
49 ms |
16640 KB |
Output is correct |
18 |
Correct |
50 ms |
16844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
7 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
12116 KB |
Output is correct |
5 |
Correct |
6 ms |
12116 KB |
Output is correct |
6 |
Correct |
8 ms |
12244 KB |
Output is correct |
7 |
Correct |
12 ms |
12728 KB |
Output is correct |
8 |
Correct |
7 ms |
12084 KB |
Output is correct |
9 |
Correct |
33 ms |
15252 KB |
Output is correct |
10 |
Correct |
7 ms |
12116 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
32 ms |
15704 KB |
Output is correct |
13 |
Correct |
61 ms |
17604 KB |
Output is correct |
14 |
Correct |
47 ms |
16716 KB |
Output is correct |
15 |
Correct |
42 ms |
16180 KB |
Output is correct |
16 |
Correct |
51 ms |
17500 KB |
Output is correct |
17 |
Correct |
66 ms |
16588 KB |
Output is correct |
18 |
Correct |
45 ms |
16900 KB |
Output is correct |
19 |
Correct |
362 ms |
40740 KB |
Output is correct |
20 |
Correct |
357 ms |
37096 KB |
Output is correct |
21 |
Correct |
292 ms |
33384 KB |
Output is correct |
22 |
Correct |
351 ms |
40848 KB |
Output is correct |
23 |
Correct |
163 ms |
27064 KB |
Output is correct |
24 |
Correct |
366 ms |
36112 KB |
Output is correct |
25 |
Correct |
376 ms |
37404 KB |
Output is correct |