제출 #1033345

#제출 시각아이디문제언어결과실행 시간메모리
1033345ziewacz어르신 집배원 (BOI14_postmen)C++17
100 / 100
287 ms65344 KiB
#include <bits/stdc++.h> #define imie(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n' using namespace std; typedef long long ll; typedef long double ld; const int MOD = 1000000007; const int MAXN = 5e5 + 5; vector<pair<int, int>> graf[MAXN]; vector<int> sciezka; vector<bool> visited(MAXN, false); vector<bool> b(MAXN, false); void dfs(int v) { while(!graf[v].empty()) { pair<int, int> p = graf[v].back(); int w = p.first; int ind = p.second; graf[v].pop_back(); if(!visited[ind]) { visited[ind] = true; dfs(w); } } sciezka.push_back(v); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i++) { int a,b; cin >> a >> b; graf[a].push_back({b,i}); graf[b].push_back({a,i}); } dfs(1); vector<int> v; reverse(sciezka.begin(), sciezka.end()); for(auto &s : sciezka) { if(b[s]) { cout << s << ' '; while(v.back() != s) { b[v.back()] = 0; cout << v.back() << ' '; v.pop_back(); } cout << '\n'; } else { b[s] = 1; v.push_back(s); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...