제출 #534815

#제출 시각아이디문제언어결과실행 시간메모리
534815Bill_00어르신 집배원 (BOI14_postmen)C++14
55 / 100
531 ms76856 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") #pragma GCC target("sse4,avx2,fma,avx") #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...