Submission #513662

# Submission time Handle Problem Language Result Execution time Memory
513662 2022-01-17T11:39:22 Z jamezzz Stations (IOI20_stations) C++17
0 / 100
893 ms 660 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(x) x.begin(),x.end()

int pre[1005],pst[1005],dist[1005],cnt;
vector<int> AL[1005];

void dfs(int u){
	pre[u]=cnt++;
	for(int v:AL[u]){
		if(pre[v]==-1){
			dist[v]=dist[u]+1;
			dfs(v);
		}
	}
	pst[u]=cnt++;
}

vector<int> label(int n,int k,vector<int> u,vector<int> v){
	vector<int> l(n);
	for(int i=0;i<n;++i)AL[i].clear();
	memset(pre,-1,sizeof pre);
	memset(pst,-1,sizeof pst);
	cnt=0;
	for(int i=0;i<n-1;++i){
		AL[u[i]].pb(v[i]);
		AL[v[i]].pb(u[i]);
	}
	dist[0]=0;dfs(0);
	vector<int> d;
	for(int i=0;i<n;++i){
		if(dist[i]%2)d.pb(pre[i]);
		else d.pb(pst[i]);
	}
	sort(all(d));
	d.resize(unique(all(d))-d.begin());
	for(int i=0;i<n;++i){
		if(dist[i]%2)l[i]=lower_bound(all(d),pre[i])-d.begin();
		else l[i]=lower_bound(all(d),pst[i])-d.begin();
	}
	return l;
}

int find_next_station(int s,int t,vector<int> c){
	int n=c.size();
	if(t<c[0]){
		int pv=s;
		for(int i=0;i<n-1;++i){
			if(pv+1<=t&&t<=c[i])return c[i];
			pv=c[i];
		}
		return c[n-1];
	}
	else{
		int pv=s;
		for(int i=n-1;i>=1;--i){
			if(c[i]<=t&&t<=pv-1)return c[i];
			pv=c[i];
		}
		return c[0];
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 528 ms 496 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 497 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 545 ms 660 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 893 ms 520 KB Output is correct
2 Incorrect 723 ms 404 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 379 ms 624 KB Wrong query response.
2 Halted 0 ms 0 KB -