# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
320013 | neki | Race (IOI11_race) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "race.h"
#include <bits/stdc++.h>
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll int
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 201000
#define pa pair<ll, ll>
#define ld long double
vc<pa> edg[mn];
ll n, k, vis[mn], ans=0;
ll fnd(ll st){
vc<ll> sz(n, 1);
function<void (ll, ll)> psa=[&](ll u, ll p){
fore(v, edg[u]) if(!vis[v.fi] and v.fi!=p) psa(v.fi, u), sz[u]+=sz[v.fi];
};
psa(st, -1);
function<ll (ll, ll)> dfs=[&](ll u, ll p){
fore(v, edg[u]) if(!vis[v.fi] and v.fi!=p and sz[v.fi]>n/2) return dfs(v.fi, u);
return u;
};
return dfs(st, -1);
}
vc<ll> cur;
void getd(ll u, ll p, ll dist){
cur.ps(dist);
fore(v, edg[u]) if(!vis[v.fi] and v.fi!=p) getd(v.fi, u, dist+v.se);
}
void dec(ll st){
ll c=fnd(st);
map<ll, ll> al;al[0]=1;
fore(v, edg[c]) if(!vis[v.fi]){
cur.clear();
getd(v.fi, c, v.se);
fore(d, cur) if(al.find(k-d)!=al.end()) ans+=al[k-d];
fore(d, cur) al[d]++;
}
vis[c]=1;
fore(v, edg[c]) if(!vis[v.fi]) dec(v.fi);
}
ll bestpath(ll N, ll K, ll h[][2], ll l[]){
n=N, k=K;
loop(i, 0, n-1){
edg[h[i][0]].ps(make_pair(h[i][1], l[i]));
edg[h[i][1]].ps(make_pair(h[i][0], l[i]));
}
dec(0);
return ans;
}