제출 #31508

#제출 시각아이디문제언어결과실행 시간메모리
31508minkank어르신 집배원 (BOI14_postmen)C++14
55 / 100
1091 ms113380 KiB
#include <iostream> #include <set> #include <stack> using namespace std; const int N = 5e5 + 5; int n, m; set<int> s[N]; multiset<int> ss; stack<int> st; void dfs(int u) { while(s[u].size()) { int v = *s[u].begin(); s[u].erase(v); s[v].erase(u); dfs(v); } if(ss.find(u) != ss.end()) { while(st.top() != u) { cout << st.top() << ' '; multiset<int>::iterator it = ss.find(st.top()); ss.erase(it); st.pop(); } cout << u; multiset<int>::iterator it = ss.find(st.top()); ss.erase(it); st.pop(); cout << endl; } st.push(u); ss.insert(u); } int main() { cin >> n >> m; for(int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; s[u].insert(v); s[v].insert(u); } dfs(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...