답안 #281798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281798 2020-08-23T13:34:18 Z PKhing 경주 (Race) (IOI11_race) C++14
9 / 100
478 ms 22568 KB
#include "race.h"
#include<bits/stdc++.h>
#define FOR(i,a) for(int i=0;i<a;i++)
#define FOR1(i,a) for(int i=1;i<=a;i++)
#define db(a) printf("<%d> ",a)
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb emplace_back
#define p emplace
#define ii pair<int,int>
#define ll long long
#define rf() freopen("_working/input.in","r",stdin)
#define pf() freopen("_working/output.out","w+",stdout)
using namespace std;
const int INF=1e9;
int size[200005];
queue<ii> len;
set<ii> edge[200005];
int ans = INF;
int centroid(int u,int p,int n){
  for(auto v:edge[u]){
    if(v.f!=p && size[v.f]>n/2)return centroid(v.f,u,n);
  }
  return u;
}
void dfs(int u,int p){
  size[u]=1;
  for(auto v:edge[u]){
    if(v.f!=p){
      dfs(v.f,u);
      size[u]+=size[v.f];
    } 
  }
}
void setlen(int u,int p,int l,int cnt,int cen){
  len.p(l,cnt);
  for(auto v:edge[u]){
    if(v.f!=p){
      setlen(v.f,u,l+v.s,cnt+1,cen);
    }
  }
}
int k;
int decomp(int u,int p){
  set<ii> f,tmp;
  dfs(u,-1);
  int x = centroid(u,-1,size[u]);
  for(auto v:edge[x]){
      setlen(v.f,x,v.s,1,x);
    while(!len.empty()){
      tmp.p(len.front());
      auto x = f.upper_bound(mp(k-len.front().f,-1));
      if(x->f == k-len.front().f)ans = min(ans,x->s+len.front().s);
      len.pop();
    }
    for(auto i:tmp){
        f.insert(i);
    }
    tmp.clear();
  }
  for(auto v:edge[x]){
    edge[v.f].erase(mp(x,v.s));
    decomp(v.f,x);
  }
  edge[x].clear();
  return x;
}
int best_path(int N, int K, int H[][2], int L[])
{
  k=K;
  for(int i=0;i<N-1;i++){
    edge[H[i][0]].p(H[i][1],L[i]);
    edge[H[i][1]].p(H[i][0],L[i]);
  }
  decomp(0,-1);
  return ans==1e9?-1:ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 8 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 8 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Incorrect 6 ms 9728 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 8 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Incorrect 478 ms 22568 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 7 ms 9728 KB Output is correct
5 Correct 7 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 7 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 7 ms 9728 KB Output is correct
12 Correct 7 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 8 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 8 ms 9728 KB Output is correct
20 Incorrect 6 ms 9728 KB Output isn't correct
21 Halted 0 ms 0 KB -