답안 #982374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982374 2024-05-14T07:39:36 Z Godgift42 경주 (Race) (IOI11_race) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;


vector<vector<pair<int,int>>> adj;
int n, k;
vector<int> subtr;
vector<bool> vis;
unordered_map<int,int> mp;
int ans=INT_MAX;

void findsize(int u, int p){
    subtr[u]=1;
    for(auto [v,w]:adj[u]){
        if(v!=p and !vis[v]){
            findsize(v,u);
            subtr[u]+=subtr[v];
        }
    }
}

int findcentroid(int u, int p, int sz){
    for(auto [v,w]:adj[u]){
        if(v!=p and !vis[v] and subtr[v]>sz/2)return findcentroid(v,u,sz);
    }
    return u;
}

void dfs1(int u, int p, int dist, int depth){
    if(dist>k)return;
    if(mp[k-dist] or k==dist) ans=min(ans,mp[k-dist]+depth);
    for(auto [v,w]:adj[u]){
        if(v!=p and !vis[v]){
            dfs1(v,u,dist+w,depth+1);
        }
    }
}

void dfs2(int u, int p, int dist, int depth){
    if(dist>k)return;
    if(mp[dist]==0)mp[dist]=depth;
    else mp[dist]=min(mp[dist],depth);
    for(auto [v,w]:adj[u]){
        if(v!=p and !vis[v]){
            dfs2(v,u,dist+w,depth+1);
        }
    }
}

void buildcentroid(int u, int p){
    findsize(u,u);
    int c=findcentroid(u,u,subtr[u]);
    vis[c]=true;
    for(auto [v,w]:adj[c]){
        if(v!=p and !vis[v]){
            dfs1(v,c,w,1);
            dfs2(v,c,w,1);
        }
    }
    mp.clear();
    for(auto [v,w]:adj[c]){
        if(!vis[v])buildcentroid(v,c);
    }
}

int bestpath(int N, int K, int H[][2], int L[]){
    n=N;
    k=K;
    adj.resize(n);
    subtr.resize(n);
    vis.resize(n);
    for(int i=0;i<n-1;i++){
        adj[H[i][1]].push_back({H[i][0],L[i]});
        adj[H[i][0]].push_back({H[i][1],L[i]});
    }
    buildcentroid(0,-1);
    if(ans==INT_MAX)return -1;
    return ans;
}

Compilation message

race.cpp: In function 'void findsize(int, int)':
race.cpp:14:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'int findcentroid(int, int, int)':
race.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'void dfs1(int, int, int, int)':
race.cpp:32:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'void dfs2(int, int, int, int)':
race.cpp:43:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |     for(auto [v,w]:adj[u]){
      |              ^
race.cpp: In function 'void buildcentroid(int, int)':
race.cpp:54:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   54 |     for(auto [v,w]:adj[c]){
      |              ^
race.cpp:61:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |     for(auto [v,w]:adj[c]){
      |              ^
/usr/bin/ld: /tmp/ccgGKnpz.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status