제출 #1027780

#제출 시각아이디문제언어결과실행 시간메모리
1027780anarch_y어르신 집배원 (BOI14_postmen)C++17
0 / 100
1 ms2652 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) begin(x), end(x) #define sz(x) (int)x.size() #define pb push_back const int maxn = 100001; vector<pair<int, int>> adj[maxn]; vector<bool> seen; vector<pair<int, int>> path; void dfs(int s, int i){ while(!adj[s].empty()){ auto [u, id] = adj[s].back(); adj[s].pop_back(); if(seen[id]) continue; seen[id] = true; dfs(u, id); } path.pb({s, i}); } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; seen.resize(m+1); for(int i=1; i<=m; i++){ int a, b; cin >> a >> b; adj[a].pb({b, i}); adj[b].pb({a, i}); } dfs(1, 0); reverse(all(path)); int v[n+1] = {}; vector<pair<int, int>> w; for(auto [s, i]: path){ if(v[s]){ cout << i << ' '; while(w.back().first != s){ auto [t, j] = w.back(); w.pop_back(); v[t] = 0; cout << j << ' '; } cout << "\n"; } else{ v[s] = 1; w.pb({s, i}); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...