Submission #536356

#TimeUsernameProblemLanguageResultExecution timeMemory
536356ShelterSenior Postmen (BOI14_postmen)C++14
55 / 100
552 ms90500 KiB
#include <bits/stdc++.h> #define len(x) (int)(x).size() #define range(i, x, y) for(int i=x; i<y; i++) #define sws ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vint vector<int> #define vll vector<long long> #define vstr vector<string> #define ll long long #define F first #define S second #define pb push_back #define pf push_front #define del(a, n) (a).erase(a.begin()+(n)) #define mp make_pair #define all(a) (a.begin(), a.end()) const int MAX = 1e6 + 1; using namespace std; vint sol; vint res; bool dead[MAX]; vector<array<ll, 2>> gra[MAX]; void dfs(int u) { while(!gra[u].empty()) { while(!gra[u].empty() && dead[gra[u].back()[1]]) gra[u].pop_back(); if(!gra[u].empty()) { dead[gra[u].back()[1]] = true; dfs(gra[u].back()[0]); } } sol.push_back(u); } bool vs[MAX]; void decompose() { stack<int> cur; vector<vint> re; for(int u:sol) { if(!vs[u]) { cur.push(u); vs[u] = 1; } else { vint cyc; while(vs[u]) { cyc.pb(cur.top()); vs[cur.top()] = 0; cur.pop(); } for(auto x : cyc){ cout << x << " "; } cout << endl; cur.push(u); vs[u] = 1; } } } int main(){ sws int n, m; cin >> n >> m; for(int i=0; i<m; i++){ int u, v; cin >> u >> v; gra[u].pb({v, i}); gra[v].pb({u, i}); } dfs(1); decompose(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...