Submission #413931

#TimeUsernameProblemLanguageResultExecution timeMemory
413931BlagojceSenior Postmen (BOI14_postmen)C++17
100 / 100
404 ms79828 KiB
#include <bits/stdc++.h> #include <cstdio> #pragma GCC optimize("O3") #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x), end(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const ll inf = 1e18; const ll mod = 1000000007; const ld eps = 1e-13; const ld pi = 3.14159265359; mt19937 _rand(time(NULL)); clock_t timer = clock(); const int mxn = 5*1e5+5; inline int readint(){ int ret=0; for(char c;;){ c=getchar_unlocked(); if('0'<=c and c<='9') ret=ret*10+(c&15); else return ret; } } vector<char> digits; inline void printint(int x){ do{ digits.push_back(x%10|48); x/=10; }while(x); while(not digits.empty()) putchar(digits.back()), digits.pop_back(); } int n, m; vector<int> g[mxn]; int deg[mxn]; bool used[mxn]; int l[mxn], r[mxn]; vector<int> cycle; void euler(int u){ while(deg[u] > 0){ int e = g[u][deg[u]-1]; int v = l[e]; if(v == u) v = r[e]; --deg[u]; if(used[e]) continue; used[e] = true; euler(v); } cycle.pb(u); } bool vis[mxn]; int main(){ digits.reserve(10); n=readint(), m=readint(); fr(i, 0, m){ l[i] = readint(), r[i] = readint(); --l[i], --r[i]; ++deg[l[i]]; ++deg[r[i]]; g[l[i]].pb(i); g[r[i]].pb(i); } euler(0); stack<int> S; for(auto u : cycle){ if(vis[u]){ while(1){ int x = S.top(); printint(x+1); putchar(' '); S.pop(); vis[x] = false; if(x == u){ putchar('\n'); break; } } } vis[u] = true; S.push(u); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...