Submission #547275

#TimeUsernameProblemLanguageResultExecution timeMemory
547275JomnoiSenior Postmen (BOI14_postmen)C++17
38 / 100
1101 ms46308 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int MAX_N = 5e5 + 10; set <pair <int, int>> graph[MAX_N]; bitset <MAX_N> visited; bool dfs(int u, int x, int p) { if(visited[u] == true) { return u == x; } visited[u] = true; for(auto [v, i] : graph[u]) { if(v == p) { continue; } if(dfs(v, x, u) == true) { graph[u].erase(make_pair(v, i)); graph[v].erase(make_pair(u, i)); cout << u << ' '; visited[u] = false; return true; } } visited[u] = false; return false; } int main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; graph[u].emplace(v, i); graph[v].emplace(u, i); } for(int i = 1; i <= n; i++) { while(!graph[i].empty()) { dfs(i, i, -1); cout << '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...