Submission #291856

#TimeUsernameProblemLanguageResultExecution timeMemory
291856BlagojceSenior Postmen (BOI14_postmen)C++11
55 / 100
624 ms71052 KiB
#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 = 5*1e5+5;

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){
	while(!g[u].empty()){
		int e = g[u].back();
		int v = nxt(u, e);
		g[u].pop_back();
		
		if(used[e]) continue;
		used[e] = true;
		
		euler(v);
	}
	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)

postmen.cpp: In function 'void solve()':
postmen.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   84 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |   scanf("%d %d", &l[i], &r[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...