제출 #534813

#제출 시각아이디문제언어결과실행 시간메모리
534813Bill_00어르신 집배원 (BOI14_postmen)C++14
55 / 100
583 ms76876 KiB
#include <bits/stdc++.h> #define N 500005 using namespace std; int vis[N], p[N]; int n, m, pre; set<int> adj[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++){ int a, b; cin >> a >> b; adj[a].insert(b); adj[b].insert(a); } for(int i = 1; i <= n; i++){ while(adj[i].size()){ stack<int> s; s.push(i); while(s.size()){ int now = s.top(); // cout << now << ' '; if(vis[now] == 1){ // cout << 1 << '\n'; cout << now << ' '; s.pop(); while(s.top() != now){ vis[s.top()] = 0; cout << s.top() << ' '; s.pop(); } vis[now] = 0; cout << '\n'; } else{ if(adj[now].size() == 0){ vis[now] = 2; s.pop(); // cout << 2 << '\n'; } else{ // cout << 3 << '\n'; vis[now] = 1; int k = *adj[now].begin(); adj[now].erase(k); adj[k].erase(now); s.push(k); } } } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...