제출 #210015

#제출 시각아이디문제언어결과실행 시간메모리
210015brcodeRace (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <race.h>
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5+5;
long long ans =1e18;
long long sz[MAXN];
bool used[MAXN];
long long n,k;
map<long long,long long> m1;
vector<pair<long long,long long>> toadd;
long long currsz = 0;
vector<pair<long long,long long>> v1[MAXN];

void dfs(long long curr,long long par){
    currsz++;
    sz[curr] = 1;
    for(auto x:v1[curr]){
        if(!used[x.first] && x.first!=par){
            dfs(x.first,curr);
            sz[curr]+=sz[x.first];
        }
    }
}
long long centroid(long long curr,long long par){
    for(auto x:v1[curr]){
        if(!used[x.first] && x.first!=par && sz[x.first]>currsz/2){
            return centroid(x.first,curr);
        }
    }
    return curr;
}
void dfsans(long long curr,long long par,long long val,long long depth){
    for(auto x:v1[curr]){
        if(x.first!=par && !used[x.first]){
            toadd.push_back(make_pair(val+x.second,depth+1));
            dfsans(x.first,curr,val+x.second,depth+1);
        }
    }
}
void decompose(long long u,long long par){
    currsz = 0;
    dfs(u,u);
    long long cen = centroid(u,u);
    //cout<<cen<<endl;
    //link[cen] = par;
    //find all paths through the centroid
    m1.clear();
    for(auto x:v1[cen]){
        if(!used[x.first]){
            
            toadd.clear();
            toadd.push_back(make_pair(x.second,1));
            dfsans(x.first,cen,x.second,1);
            
        }
        for(auto y:toadd){
            if(cen == 1){
             //   cout<<x.first<<" "<<y.first<<" "<<123<<endl;
            }
            if(k-y.first>=0 && m1[k-y.first]){
              //  cout<<cen<<" "<<m1[k-y.first]+y.second<<endl;
                ans = min(ans,m1[k-y.first]+y.second);
            }
            if(y.first == k){
                ans = min(ans,y.second);
            }
        }
        for(auto y:toadd){
           // cout<<cen<<" "<<y.first<<" "<<y.second<<endl;
           
            if(!m1[y.first]){
                m1[y.first] = y.second;
            }else{
                m1[y.first] = min(m1[y.first],y.second);
            }
            
            
        }
    }
    
    used[cen] = true;
    for(auto x:v1[cen]){
        if(!used[x.first]){
            decompose(x.first,cen);
        }
    }
    used[cen] = false;
}
long long best_path(long long N,long long K,long long H[][2],long long L[]){
    n = N;
    k = K;
    for(long long i=0;i<n-1;i++){
        long long u = H[i][0];
        long long v = H[i][1];
        long long w = L[i];
        u++;v++;
        v1[u].push_back(make_pair(v,w));
        v1[v].push_back(make_pair(u,w));
    }
    decompose(1,1);
    if(ans == 1e9){
        return -1;
    }
    return ans;
}

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

/tmp/cc2OTMZa.o: In function `main':
grader.cpp:(.text.startup+0x20): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status