제출 #899276

#제출 시각아이디문제언어결과실행 시간메모리
899276selmahbn어르신 집배원 (BOI14_postmen)C++17
55 / 100
594 ms83540 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(); cout.tie(); int n, m; cin >> n >> m; vector<multiset<int>> adj(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; adj[a].insert(b); adj[b].insert(a); } stack<int> s; vector<int> visited(n, 0); for (int i = 0; i < n; i++) { s.push(i); while (!s.empty()) { int current = s.top(); if (visited[current] == 1) { cout << current+1 << " "; s.pop(); while (s.top() != current) { cout << s.top()+1 << " "; visited[s.top()] = 0; s.pop(); } cout << endl; } visited[current] = 1; if (!adj[current].empty()) { auto it = adj[current].begin(); s.push(*it); adj[current].erase(it); adj[*it].erase(adj[*it].find(current)); } else { s.pop(); visited[current] = 0; } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...