Submission #418578

#TimeUsernameProblemLanguageResultExecution timeMemory
418578BertedSenior Postmen (BOI14_postmen)C++14
55 / 100
503 ms71528 KiB
#include <iostream> #include <vector> #define pii pair<int, int> #define fst first #define snd second using namespace std; const int INF = 1e9; int N, M, H[500001]; vector<pii> adj[500001]; bool used[500001]; int DFS(int u) { while (adj[u].size()) { int v = adj[u].back().fst, id = adj[u].back().snd; adj[u].pop_back(); if (used[id]) continue; used[id] = 1; if (H[v] < H[u]) { cout << u + 1 << " "; H[u] = INF; return H[v]; } H[v] = H[u] + 1; int ret = DFS(v); if (ret < H[u]) { cout << u + 1 << " "; H[u] = INF; return ret; } if (ret == H[u]) {cout << u + 1 << "\n";} } H[u] = INF; return INF; } int main() { cin.tie(0) -> sync_with_stdio(0); cin >> N >> M; for (int i = 0; i < N; i++) H[i] = INF; for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; adj[u - 1].push_back({v - 1, i}); adj[v - 1].push_back({u - 1, i}); } for (int i = 0; i < N; i++) { if (adj[i].size()) {H[i] = 0; DFS(i);} } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...