제출 #56456

#제출 시각아이디문제언어결과실행 시간메모리
56456Bodo171경주 (Race) (IOI11_race)C++14
100 / 100
1507 ms207056 KiB
#include "race.h"
#include <vector>
#include <map>
#include <iostream>
using namespace std;
const int nmax=200005;
map<long long,int> m[nmax];
vector< pair<int,int> > v[nmax];
long long k;
long long L[nmax];
int rr[nmax],l[nmax],r[nmax],lev[nmax],w[nmax],p[nmax];
int mn,nr,paths,n,i;
void ver(int path,long long A,long long LCA,int lca,int x)
{
    //A+X-2*LCA=K
    //X=K-A+2*LCA
    if(m[path][k-A+2*LCA]&&m[path][k-A+2*LCA]+x-2*lca<mn)
        mn=m[path][k-A+2*LCA]+x-2*lca;
}
void baga(int path,long long A,int x)
{
    if((!m[path][A])||m[path][A]>x)
        m[path][A]=x;
}
void dfs(int x)
{
    int son=n+1,nod=0;
    rr[++nr]=x;l[x]=nr;w[x]=1;
    for(int i=0;i<v[x].size();i++)
        if(!w[v[x][i].first])
    {
        nod=v[x][i].first;
        lev[nod]=lev[x]+1;L[nod]=1LL*L[x]+v[x][i].second;
        dfs(nod);
        w[x]+=w[nod];
        if(w[nod]>w[son]) son=nod;
    }
    r[x]=nr;
    p[x]=p[son];
    if(son==n+1) p[x]=++paths;
    for(int i=0;i<v[x].size();i++)
        if(w[v[x][i].first]<=w[x]&&son!=v[x][i].first)
    {
        nod=v[x][i].first;
        for(int j=l[nod];j<=r[nod];j++)
        {
            ver(p[x],L[rr[j]],L[x],lev[x],lev[rr[j]]);
        }
        for(int j=l[nod];j<=r[nod];j++)
        {
            baga(p[x],L[rr[j]],lev[rr[j]]);
        }
    }
    ver(p[x],L[x],L[x],lev[x],lev[x]);
    baga(p[x],L[x],lev[x]);
}
int best_path(int N, int K, int H[][2], int L[])
{
  n=N,k=K;
  for(i=0;i<n-1;i++)
  {
      v[H[i][0]].push_back({H[i][1],L[i]});
      v[H[i][1]].push_back({H[i][0],L[i]});
  }
  lev[0]=1;mn=n+1;
  dfs(0);
  if(mn==n+1) mn=-1;
  return mn;
}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In function 'void dfs(int)':
race.cpp:29:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
race.cpp:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...