Submission #727280

#TimeUsernameProblemLanguageResultExecution timeMemory
727280TigerpantsSenior Postmen (BOI14_postmen)C++17
55 / 100
521 ms85084 KiB
#include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> #include <numeric> #include <functional> #include <unordered_set> using namespace std; typedef long long int ll; typedef vector<ll> vll; typedef set<ll> sll; typedef vector<vll> vvll; typedef vector<sll> vsll; typedef vector<bool> vb; typedef unordered_set<ll> usll; typedef vector<usll> vusll; #define rep(i, a, b) for (ll i = a; i < b; i++) #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define sz(a) a.size() ll N, M; vvll g; vll pr; vll S; vb onS; vb vis; vll e[2]; ll getU(ll i, ll v) { return (v == e[0][i]) ? e[1][i] : e[0][i]; } bool DFS(ll cur) { if (onS[cur]) { // found axon cout << cur + 1 << " "; onS[cur] = false; return true; } else { onS[cur] = true; S.pb(cur); while (pr[cur] >= 0) { ll edge = g[cur][pr[cur]]; pr[cur]--; if (vis[edge]) { continue; } ll nxt = getU(edge, cur); vis[edge] = true; if (DFS(nxt)) { if (onS[cur]) { cout << cur + 1 << " "; onS[cur] = false; S.pop_back(); return true; } else { onS[cur] = true; cout << "\n"; } } } S.pop_back(); return false; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> M; g.resize(N); pr.resize(N, -1); e[0].resize(M); e[1].resize(M); rep(i, 0, M) { cin >> e[0][i] >> e[1][i]; e[0][i]--; e[1][i]--; g[e[0][i]].pb(i); pr[e[0][i]]++; g[e[1][i]].pb(i); pr[e[1][i]]++; } onS.resize(N, false); vis.resize(M, false); rep(i, 0, N) { DFS(i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...