제출 #445711

#제출 시각아이디문제언어결과실행 시간메모리
445711MohammadAghil어르신 집배원 (BOI14_postmen)C++14
100 / 100
466 ms67684 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i,l,r) for(int i = (l); i < r; i++) #define per(i,r,l) for(int i = (r); i >= l; i--) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define pb push_back #define ff first #define ss second const ll mod = 1e9 + 7,maxlg = 22, maxn = 5e5 + 5, inf = 1e9 + 5, p = 9973; bool vis[maxn]; int ptr[maxn]; vector<pair<int, int>> adj[maxn]; vector<int> tour; void dfs(int r){ while(ptr[r] != sz(adj[r])){ int id = adj[r][ptr[r]].ss, c = adj[r][ptr[r]].ff; ptr[r]++; if(!vis[id]){ vis[id] = 1; dfs(c); } } tour.pb(r); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; rep(i,0,m){ int u, v; cin >> u >> v; u--, v--; adj[u].pb({v, i}); adj[v].pb({u, i}); } dfs(0); vector<int> st; vector<bool> in_st(n); rep(i,0,sz(tour)){ if(in_st[tour[i]]){ cout << tour[i] + 1 << ' '; while(st.back() != tour[i]){ cout << st.back() + 1 << ' '; in_st[st.back()] = 0; st.pop_back(); } cout << '\n'; }else{ st.pb(tour[i]); in_st[tour[i]] = 1; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...