이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
using ull = unsigned long long;
using str = string;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const int nax = 200010;
vector<int>flag(nax);
set<int>adj[nax];
vector<int>pracka;
void Euler(int v){
while(adj[v].size() > 0){
int x = *adj[v].begin();
adj[v].erase(x);
adj[x].erase(v);
Euler(x);
}
pracka.pb(v);
}
void solve(){
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++){
int a,b;
cin >> a >> b;
--a,--b;
adj[a].insert(b);
adj[b].insert(a);
}
Euler(0);
int r = -1;
vector<vector<int>>cycles;
vector<int>visited(n + 1);
stack<int>c;
while(r < (int)pracka.size()){
++r;
if (visited[pracka[r]]){
cycles.push_back(vector<int>());
cycles.back().push_back(pracka[r]);
while(c.top() != pracka[r]){
visited[c.top()] = 0;
cycles.back().push_back(c.top());
c.pop();
}
}else{
c.push(pracka[r]);
visited[pracka[r]] = 1;
}
}
for (int i = 0; i < (int)cycles.size() - 1; i++){
for (int j : cycles[i])cout << ++j << " ";
cout << '\n';
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |