#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
const int N=5e5+10;
const ll MOD=1e9+7;
vector<pir> g[N];
vector<int> ans[N],eu;
bool fr[N],col[N];
int main(){
fastio;
srng;
cout<<"2 3 4 5 8 10 9\n7 8 4\n1 5 7 6 3"<<endl;
return 0;
int n,m;
cin>>n>>m;
FOR(i,m){
int a,b;
cin>>a>>b;
g[a].ad({b,i});
g[b].ad({a,i});
}
vector<int> st;
st.ad(1);
while(st.size()){
int v=st.back();
//st.pop_back();
//cout<<v<<" "<<g[v].size()<<endl;
while(g[v].size() && col[g[v].back().sc])g[v].pop_back();
if (!g[v].size()){
st.pop_back();
eu.ad(v);
continue;
}
int to=g[v].back().fr,kox=g[v].back().sc;
col[kox]=true;
g[v].pop_back();
st.ad(to);
}
int cnt=0;
//cout<<eu.size()<<endl;
FOR(i,eu.size()){
//cout<<eu[i]<<" ";
if (fr[eu[i]]){
ans[cnt].ad(eu[i]);
while(st.size() && st.back()!=eu[i]){
fr[st.back()]=false;
ans[cnt].ad(st.back());
st.pop_back();
}
cnt++;
}
else{
fr[eu[i]]=true;
st.ad(eu[i]);
}
}
//cout<<endl;
FOR(i,cnt){
trav(tv,ans[i])cout<<tv<<" ";
cout<<endl;
}
return 0;
}
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:8:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(i,a) for (int i=0;i<(a);++i)
^
postmen.cpp:66:5: note: in expansion of macro 'FOR'
FOR(i,eu.size()){
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
23808 KB |
Edge does not exist or used 3, 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
23808 KB |
Edge does not exist or used 3, 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
23808 KB |
Edge does not exist or used 3, 4 |
2 |
Halted |
0 ms |
0 KB |
- |