이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
//#define ll long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e6 + 100, OO = 1e9 + 7, K = 1e7 + 4, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
bool mark[N];
int num[N];
vector <pii> v[N];
vector <int> ET;
void dfs(int x) {
while((int)v[x].size()) {
pii p = v[x].back();
v[x].pop_back();
if(mark[p.ss])
continue;
mark[p.ss] = true;
dfs(p.ff);
ET.pb(x);
}
}
int32_t main() {
use_fast;
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].pb({y, i});
v[y].pb({x, i});
}
dfs(1);
vector <int> ht;
for(auto u : ET) {
if(num[u]) {
cout << u;
while(ht.back() != u)
cout << " " << ht.back(), num[ht.back()]--, ht.pop_back();
cout << endl;
// for(auto u : ht)
// cout << u << " ";
// return 0;
}
else
ht.pb(u), num[u]++;
}
for(auto u : ht)
cout << u << " ";
cout << endl;
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... |