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;
#define pb push_back
#define sz size
#define all(x) begin(x), end(x)
#define ll long long
#define INF 1e18
#define MOD (int)(1e9 + 7)
int N, M, cnt[500005];
vector<pair<int, int>> adj[500005];
vector<int> cycle;
vector<vector<int>> cycles;
bool seen[500005];
void dfs(int v) {
while(adj[v].sz()) {
pair<int, int> p = adj[v].back();
adj[v].pop_back();
int u = p.first, id = p.second;
if(!seen[id]) {
seen[id] = true;
dfs(u);
}
}
cycle.pb(v);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
for(int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
adj[a].pb({b, i});
adj[b].pb({a, i});
}
dfs(1);
stack<int> st;
for(int i = 0; i < cycle.sz(); ++i) {
int u = cycle[i];
cnt[u]++;
st.push(u);
if(cnt[u] > 1) {
vector<int> v;
v.pb(u), st.pop();
while(st.top() != u) {
int p = st.top();
v.pb(p);
cnt[p]--;
st.pop();
}
cnt[u] -= 2;
cycles.pb(v);
}
}
for(auto const &cyc : cycles) {
for(int v : cyc)
cout << v << ' ';
cout << '\n';
}
return 0;
}
Compilation message (stderr)
postmen.cpp: In function 'int main()':
postmen.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 0; i < cycle.sz(); ++i) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |