Submission #697720

#TimeUsernameProblemLanguageResultExecution timeMemory
697720mousebeaverSenior Postmen (BOI14_postmen)C++14
55 / 100
628 ms160496 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<unordered_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<unordered_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); } tour.push(i); instack[i] = true; 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...