제출 #1119608

#제출 시각아이디문제언어결과실행 시간메모리
1119608vjudge1어르신 집배원 (BOI14_postmen)C++17
55 / 100
766 ms136996 KiB
#include <bits/stdc++.h> #define ll long long #define fr(i, d, c) for(ll i = d; i <= c; i++) #define fl(i, d, c) for(ll i = d; i >= c; i--) const int N = 5e5 + 9; using namespace std; ll n, m; map<ll, ll> dd; set<ll> adj[N]; stack<ll> st; void run(ll u, ll bd) { dd[u] = true; st.push(u); ll v = *adj[u].rbegin(); adj[u].erase(v); adj[v].erase(u); if(dd[v] == true) { while(true) { ll t = st.top(); st.pop(); cout<<t<<" "; dd[t] = false; if(t == v) break; } cout<<'\n'; } if(v != bd) run(v, bd); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; fr(i, 1, m) { ll x, y; cin>> x >> y; adj[x].insert(y); adj[y].insert(x); } fr(i, 1, n) { while(adj[i].size()) { dd.clear(); run(i, i); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...