Submission #656492

#TimeUsernameProblemLanguageResultExecution timeMemory
656492600MihneaSenior Postmen (BOI14_postmen)C++17
100 / 100
405 ms75488 KiB
bool home = 0; #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 500000 + 7; int n; int m; int sum[N]; bool vis[N]; vector<int> g[N]; vector<int> ord; void go(int a) { while (!g[a].empty()) { int i = g[a].back(); g[a].pop_back(); if (vis[i]) { continue; } vis[i] = 1; go(sum[i] - a); ord.push_back(a); } } signed main() { if (home == 0) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } else { freopen ("___input___.txt", "r", stdin); } cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; sum[i] = a + b; g[a].push_back(i); g[b].push_back(i); } go(1); for (int i = 1; i <= m; i++) { assert(vis[i]); } for (int i = 1; i <= n; i++) { vis[i] = 0; } assert((int) ord.size() == m); assert(!ord.empty()); ord.push_back(ord[0]); vector<int> stk; for (auto &x : ord) { if (vis[x] == 0) { stk.push_back(x); vis[x] = 1; continue; } cout << x << " "; while (stk.back() != x) { cout << stk.back() << " "; vis[stk.back()] = 0; stk.pop_back(); } cout << "\n"; } return 0; while ((int) ord.size() > 1) { int dim = (int) ord.size(); set<int> s; for (int r = 0; r < dim; r++) { int x = ord[r]; if (s.count(x)) { s.clear(); int l = r; s.insert(ord[l]); while (!s.count(ord[l - 1])) { l--; s.insert(ord[l]); } vector<int> new_ord, now; for (int j = 0; j < dim; j++) { if (l <= j && j <= r) { now.push_back(ord[j]); continue; } new_ord.push_back(ord[j]); } for (auto &v : now) { cout << v << " "; } cout << "\n"; ord = new_ord; break; } else { s.insert(x); } } } if (0) { cout << " ---> "; for (auto &x : ord) { cout << x << " "; } cout << "\n"; } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:33:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen ("___input___.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...