Submission #1199647

#TimeUsernameProblemLanguageResultExecution timeMemory
1199647edga1경주 (Race) (IOI11_race)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

int best_path(int n, int k, int h[][2], int l[]){
    vector<pair<int,int>> a[n];
    for(int i=0; i<n-1; i++){
        a[h[i][0]].push_back({h[i][1],l[i]});
        a[h[i][1]].push_back({h[i][0],l[i]});
    }
    int m=1e9;
    vector<int> s(n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++) s[j]=0;
        queue<pair<int,int>> q,q2;
        q.push({i,0});
        int dist=0;
        while(!q.empty()){
            pair<int,int> pos=q.front();
            q.pop();
            int x=pos.first, v=pos.second;
            s[x]=1;
            if(v==k){
                m=min(m,dist);
            }
            if(v>=k) continue;
            for(int j=0; j<a[x].size(); j++){
                if(!s[a[x][j].first]){
                    q2.push({a[x][j].first,a[x][j].second+v});
                }
            }
            if(q.empty()){
                swap(q,q2);
                dist++;
            }
        }
    }
    if(m==1e9) return -1;
    return m;
}

int main(){
    int n,k;
    cin>>n>>k;
    int h[n-1][2], l[n-1];
    for(int i=0; i<n-1; i++){
        cin>>h[i][0]>>h[i][1]>>l[i];
    }
    cout<<best_path(n,k,h,l);
}

Compilation message (stderr)

/usr/bin/ld: /tmp/cc93XIg3.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwOoxSk.o:race.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status