Submission #697714

#TimeUsernameProblemLanguageResultExecution timeMemory
697714mousebeaverSenior Postmen (BOI14_postmen)C++14
0 / 100
1 ms324 KiB
#define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define pli pair<ll, int> #define pil pair<int, ll> #define pdi pair<double, int> #define pcc pair<char, char> #define tiii tuple<int, int, int> #define tlii tuple<int, int, int> #define tl tuple<ll, ll, ll, ll> #define tls tuple<ll, ll, ll> #define INF numeric_limits<ll>::max()/2 #define MOD 1000000007 #define MIO 1000000 #define mp make_pair #include <bits/stdc++.h> using namespace std; void hierholzer(int i, vector<set<int>>& adjlist, vector<int>& output) { while(adjlist[i].size()) { int j = *adjlist[i].begin(); adjlist[i].erase(j); adjlist[j].erase(i); hierholzer(j, adjlist, output); output.push_back(j); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin>>n>>m; vector<set<int>> adjlist(n); for(int i = 0; i < m; i++) { int a, b; cin>>a>>b; a--; b--; adjlist[a].insert(b); adjlist[b].insert(a); } vector<int> output(0); hierholzer(0, adjlist, output); output.push_back(0); reverse(output.begin(), output.end()); /*for(int i : output) { cout<<i+1<<" "; } cout<<"\n";*/ stack<int> tour; vector<bool> instack(n, false); for(int i : output) { if(instack[i]) { vector<int> senior(0); int v = -1; while(v != i) { v = tour.top(); tour.pop(); instack[v] = false; senior.push_back(v); } for(int j : senior) { cout<<j+1<<" "; } cout<<"\n"; } else { tour.push(i); instack[i] = true; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...