제출 #636294

#제출 시각아이디문제언어결과실행 시간메모리
636294tvladm2009어르신 집배원 (BOI14_postmen)C++14
100 / 100
436 ms77968 KiB
#include <iostream> #include <vector> using namespace std; const int MAX_N = 5 * 1e5; int in[MAX_N + 1], out[MAX_N + 1]; vector<int> g[MAX_N + 1], aux; bool viz[MAX_N + 1], b[MAX_N + 1]; int n, m; void dfs(int u) { while(g[u].size()) { int e=g[u].back(); g[u].pop_back(); if(viz[e]) continue; viz[e]=1; dfs(in[e]^out[e]^u); aux.push_back(u); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> in[i] >> out[i]; in[i]--; out[i]--; g[in[i]].push_back(i); g[out[i]].push_back(i); } aux.push_back(0); dfs(0); vector<int> sol; for (int it : aux) { if (b[it] == true) { while (b[it] == true) { cout << sol.back() + 1 << " "; b[sol.back()] = false; sol.pop_back(); } cout << "\n"; } b[it] = true; sol.push_back(it); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...