Submission #479872

#TimeUsernameProblemLanguageResultExecution timeMemory
479872SamAndSenior Postmen (BOI14_postmen)C++98
55 / 100
520 ms104000 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 500005; int n, m; int z; bool c[N]; int s[N]; vector<int> a[N]; vector<int> b[N]; int vn; int v[N]; void dfs(int x) { while (s[x] != -1) { int h = a[x][s[x]]; if (c[b[x][s[x]]]) { --s[x]; continue; } c[b[x][s[x]]] = true; --s[x]; dfs(h); } v[vn++] = x; } int ka() { int x = 0; while (1) { char t = getchar(); if (t == ' ' || t == '\n') return x; x *= 10; x += (t - '0'); } } char t[10]; void tp(int x) { int tn = 0; while (x) { t[tn++] = (x % 10) + '0'; x /= 10; } for (int i = tn - 1; i >= 0; --i) putchar(t[i]); putchar(' '); } int main() { n = ka(); m = ka(); for (int i = 0; i < m; ++i) { int x, y; x = ka(); y = ka(); a[x].push_back(y); a[y].push_back(x); ++z; b[x].push_back(z); b[y].push_back(z); } for (int i = 1; i <= n; ++i) s[i] = a[i].size() - 1; dfs(1); memset(c, false, sizeof c); stack<int> s; for (int i = 0; i < vn; ++i) { if (c[v[i]]) { tp(v[i]); while (s.top() != v[i]) { tp(s.top()); c[s.top()] = false; s.pop(); } putchar('\n'); } else { s.push(v[i]); c[v[i]] = true; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...