# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291853 | Blagojce | Senior Postmen (BOI14_postmen) | C++11 | 598 ms | 75616 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#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 = 6*1e5;
int n, m;
vector<int> g[mxn];
bool used[mxn];
int l[mxn], r[mxn];
vector<int> cycle;
int nxt(int u, int edge){
return l[edge]^r[edge]^u;
}
void euler(int u){
fr(i, 0, (int)g[u].size()){
if(used[g[u][i]]){
swap(g[u][i], g[u].back());
g[u].pop_back();
--i;
continue;
}
used[g[u][i]] = true;
euler(nxt(u, g[u][i]));
}
cycle.pb(u);
}
vector<int> sol[mxn];
int R[mxn];
int _next[mxn];
int lst[mxn];
void restore(){
for(int i = cycle.size()-1; i >= 0; i --){
_next[i] = lst[cycle[i]];
lst[cycle[i]] = i+1;
}
sol[0].pb(0);
R[0] = _next[0];
stack<int> S;
S.push(0);
int id = 1;
fr(i, 1, (int)cycle.size()-1){
int u = cycle[i];
if(R[S.top()] == i+1) S.pop();
if(S.empty() || (_next[i] != 0 && _next[i] <= R[S.top()])){
S.push(id);
sol[id].pb(u);
R[id] = _next[i];
id++;
}
else{
sol[S.top()].pb(u);
}
}
fr(i, 0, id+1){
for(auto u : sol[i]) printf("%d ", u+1);
printf("\n");
}
}
void solve(){
scanf("%d %d", &n, &m);
fr(i, 0, m){
scanf("%d %d", &l[i], &r[i]);
--l[i], --r[i];
g[l[i]].pb(i);
g[r[i]].pb(i);
}
euler(0);
restore();
}
int main(){
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |