제출 #430182

#제출 시각아이디문제언어결과실행 시간메모리
430182yanireStations (IOI20_stations)C++17
52.32 / 100
1190 ms800 KiB
#include <bits/stdc++.h>
using namespace std;
#include "stations.h"
#define fin(i,s,n) for(auto i = s; i < n; ++i)
#define fine(i,s,n) for(auto i = s; i <= n; ++i)
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
template<class T> ostream& operator<<(ostream& os, vector<T> v) {
	if(v.empty()) return os << "[]";
	os << '[' << v[0];
	fin(i,1,int(v.size())) os << ',' << v[i];
	return os << ']';
}
template<class A, class B> ostream& operator<<(ostream& os, pair<A,B> p) {
	return os << '(' << p.x << ',' << p.y << ')';
}
const int maxn = 1005;
vi l;
vi g[maxn];
int T;
void dfs(int u, int p = -1) {
	int iu = T++;
	for(int v : g[u]) if(v!=p) dfs(v,u);
	int ou = T-1;
	l[u] = 1000*iu+ou;
}
vi label(int n, int k, vi u, vi v) {
	l = vi(n,-1),T = 0;
	fin(i,0,n) g[i].clear();
	fin(i,0,n-1) g[u[i]].pb(v[i]),g[v[i]].pb(u[i]);
	dfs(0);
	return l;
}
int dir(int a, int b){ 
	if(a==b) return 0;
	return b>a?1:-1;
}
ii dcmp(int x) {
	return {x/1000,x%1000};
}
bool anc(int u, int v) {
	// while(v>=u) {
		// if(u==v) return 1;
		// v = (v-1)/2;
	// }
	// return 0;
	ii tu = dcmp(u), tv = dcmp(v);
	return tu.x <= tv.x && tu.y >= tv.y;
}
int find_next_station(int s, int t, vi c) {
	if(anc(s,t)) {
		vi ops;
		for(int v : c) if(anc(v,t)) ops.pb(v);
		if(ops.empty()) return c[0];
		return *max_element(all(ops));
	}
	for(int v : c) if(anc(v,s)) return v;
	return c[0];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...