Submission #861261

#TimeUsernameProblemLanguageResultExecution timeMemory
861261qwushaSenior Postmen (BOI14_postmen)C++17
100 / 100
349 ms86768 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma gcc optimize("Ofast") using namespace std; typedef long long ll; #define fi first #define se second typedef long double ld; const ll inf = 1e9; const ld eps = 1e-8; vector<vector<int>> g; vector<vector<int>> ans; vector<bool> used; vector<int> cur; vector<int> stcur; vector<int> res; struct vert { int to; bool used; }; vector<vert> ve; void add_vert(int v, int u) { g[v].push_back(ve.size()); ve.push_back({u, 0}); g[u].push_back(ve.size()); ve.push_back({v, 0}); } void dfs(int v) { if (stcur[v] > 0) { res.clear(); while(cur.back() != v) { stcur[cur.back()]--; res.push_back(cur.back()); cur.pop_back(); } stcur[cur.back()]--; res.push_back(cur.back()); cur.pop_back(); ans.push_back(res); } while (!g[v].empty()) { int e = g[v].back(); g[v].pop_back(); if (!ve[e].used) { cur.push_back(v); stcur[v]++; ve[e].used = 1; ve[(e ^ 1)].used = 1; dfs(ve[e].to); } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; used.resize(n); g.resize(n); for (int i = 0; i < m; i++) { int v, u; cin >> v >> u; v--; u--; add_vert(v, u); } stcur.resize(n); dfs(0); for (auto s : ans) { for (auto el : s) { cout << el + 1 << ' '; } cout << '\n'; } }

Compilation message (stderr)

postmen.cpp:4: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    4 | #pragma gcc optimize("Ofast")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...