Submission #525426

#TimeUsernameProblemLanguageResultExecution timeMemory
525426ShelterSenior Postmen (BOI14_postmen)C++17
0 / 100
1 ms204 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; using namespace std; void hier(unordered_set<int> gra[], int n, int m, int now){ int next = now; stack<int> path; vint sol; int value_edge[n+1]; for(int i = 0; i <= n; i++){ value_edge[i] = gra[i].size(); } path.push(now); while(!path.empty()){ if(value_edge[now]){ path.push(now); for(auto x : gra[now]){ next = x; break; } gra[now].erase(next); gra[next].erase(now); value_edge[now] --; value_edge[next] --; now = next; } else{ sol.push_back(now); now = path.top(); path.pop(); } } for(int i = sol.size()-1; i >= 0; i--){ cout << sol[i] <<" "; } } int main(){ sws int n, m; cin >> n >> m; unordered_set<int> gra[n+1]; for(int i=0; i<m; i++){ int u, v; cin >> u >> v; gra[u].insert(v); gra[v].insert(u); } while(1){ int term = 0; int check = 2; for(int i=1; i <= n; i++){ for(auto x : gra[i]){ term = x; check = 1; break; } if(check == 1) break; } if(term){ hier(gra, n, m, term); cout << "\n"; } else return 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...