제출 #314746

#제출 시각아이디문제언어결과실행 시간메모리
314746jaaguptammeRace (IOI11_race)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair<ll,ll>
#include "race.h"
using namespace std;
const ll CN=1000005;
vector<pii>g[CN];
map<ll,ll>*mp[CN];
ll dist[CN],sz[CN],dep[CN];
ll res=INT_MAX;
ll k;
void dfs(ll u,ll prev){
    sz[u]=1;
    ll mxsz=-1,mxn=-1;
    for(auto el:g[u]){
        ll v=el.first;
        ll c=el.second;
        if(v==prev)continue;
        dist[v]=dist[u]+c;
        dep[v]=dep[u]+1;
        dfs(v,u);
        sz[u]+=sz[v];
        if(sz[v]>mxsz){
            mxsz=sz[v];
            mxn=v;
        }
    }
    if(mxsz!=-1)mp[u]=mp[mxn];
    else mp[u]=new map<ll,ll>();
    if((*mp[u]).count(dist[u]))(*mp[u])[dist[u]]=min((*mp[u])[dist[u]],dep[u]);
    else (*mp[u])[dist[u]]=dep[u];


    for(auto E:g[u]){
        ll v=E.first;
        if(v==prev ||v==mxn)continue;
        for(auto el:(*mp[v])){
            ll nx=el.first;
             ll de=el.second;
             if((*mp[u]).count(k-nx)){
                ll node=(*mp[u])[k-nx];
                res=min(res,abs(de-dep[u])+abs(dep[u]-node));
               // cout<<"CHANGE"<<nx<<' '<<k<<' '<<de<<' '<<res<<'\n';
             }
        }
        for(auto el:(*mp[v])){
            ll nx=el.first;
             ll de=el.second;
             if((*mp[u]).count(nx)){
                 (*mp[u])[nx]=min((*mp[u])[nx],de);
             }else  (*mp[u])[nx]=de;
        }
    }
    /*
    cout<<"NODE";
    cout<<u<<' '<<prev<<' '<<dist[u]<<' '<<dep[u]<<'\n';
    for(auto el:(*mp[u]))cout<<el.first<<' '<<el.second<<'\n';
    */
    if((*mp[u]).count(k+dist[u])){
        ll node=(*mp[u])[k+dist[u]];
        //cout<<"CHANG"<<k-dist[u]<<' '<<node<<' '<<dep[u]<<' '<<u<<'\n';
        res=min(res,abs(node-dep[u]));
    }
}
int best_path(int N, int K, int H[][2], int L[])
{
    k=K;
    for(int i=0;i<N-1;i++){
        ll u,v,c;u=H[i][0];
        v=H[i][1];
        c=L[i];
        g[u].push_back({v,c});
        g[v].push_back({u,c});
    }
    for(int i=0;i<CN;i++){
        dep[i]=0;
        dist[i]=0;
        sz[i]=0;
    }
    dep[1]=0;
    dfs(1,N);
    int ans=res;
    if(ans<=N)return ans;
    else return -1;
}
/*
int main(){
    int n=4;
    int k=7;
    int h[][2]={{0,1},{1,2},{1,3}};
    int l[]={1,2,4};
    std::cout<<best_path(n,k,h,l)<<'\n';
}
*/
/*
int main(){
    int n=11;
    int k=12;
    int h[][2]={{0,1},{0,2},{2,3},{3,4},{4,5},{0,6},{6,7},{6,8},{8,9},{8,10}};
    int l[]={3,4,5,4,6,3,2,5,6,7};
    cout<<best_path(n,k,h,l)<<'\n';
}
*/

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

race.cpp:6:7: error: 'll' does not name a type
    6 | const ll CN=1000005;
      |       ^~
race.cpp:3:18: error: 'll' was not declared in this scope
    3 | #define pii pair<ll,ll>
      |                  ^~
race.cpp:7:8: note: in expansion of macro 'pii'
    7 | vector<pii>g[CN];
      |        ^~~
race.cpp:3:21: error: 'll' was not declared in this scope
    3 | #define pii pair<ll,ll>
      |                     ^~
race.cpp:7:8: note: in expansion of macro 'pii'
    7 | vector<pii>g[CN];
      |        ^~~
race.cpp:3:23: error: template argument 1 is invalid
    3 | #define pii pair<ll,ll>
      |                       ^
race.cpp:7:8: note: in expansion of macro 'pii'
    7 | vector<pii>g[CN];
      |        ^~~
race.cpp:3:23: error: template argument 2 is invalid
    3 | #define pii pair<ll,ll>
      |                       ^
race.cpp:7:8: note: in expansion of macro 'pii'
    7 | vector<pii>g[CN];
      |        ^~~
race.cpp:7:11: error: template argument 1 is invalid
    7 | vector<pii>g[CN];
      |           ^
race.cpp:7:11: error: template argument 2 is invalid
race.cpp:7:14: error: 'CN' was not declared in this scope
    7 | vector<pii>g[CN];
      |              ^~
race.cpp:8:5: error: 'll' was not declared in this scope
    8 | map<ll,ll>*mp[CN];
      |     ^~
race.cpp:8:8: error: 'll' was not declared in this scope
    8 | map<ll,ll>*mp[CN];
      |        ^~
race.cpp:8:10: error: template argument 1 is invalid
    8 | map<ll,ll>*mp[CN];
      |          ^
race.cpp:8:10: error: template argument 2 is invalid
race.cpp:8:10: error: template argument 3 is invalid
race.cpp:8:10: error: template argument 4 is invalid
race.cpp:8:15: error: 'CN' was not declared in this scope
    8 | map<ll,ll>*mp[CN];
      |               ^~
race.cpp:9:1: error: 'll' does not name a type
    9 | ll dist[CN],sz[CN],dep[CN];
      | ^~
race.cpp:10:1: error: 'll' does not name a type
   10 | ll res=INT_MAX;
      | ^~
race.cpp:11:1: error: 'll' does not name a type
   11 | ll k;
      | ^~
race.cpp:12:10: error: variable or field 'dfs' declared void
   12 | void dfs(ll u,ll prev){
      |          ^~
race.cpp:12:10: error: 'll' was not declared in this scope
race.cpp:12:15: error: 'll' was not declared in this scope
   12 | void dfs(ll u,ll prev){
      |               ^~
race.cpp: In function 'long long int best_path(long long int, long long int, long long int (*)[2], long long int*)':
race.cpp:67:5: error: 'k' was not declared in this scope
   67 |     k=K;
      |     ^
race.cpp:69:9: error: 'll' was not declared in this scope
   69 |         ll u,v,c;u=H[i][0];
      |         ^~
race.cpp:69:18: error: 'u' was not declared in this scope
   69 |         ll u,v,c;u=H[i][0];
      |                  ^
race.cpp:70:9: error: 'v' was not declared in this scope
   70 |         v=H[i][1];
      |         ^
race.cpp:71:9: error: 'c' was not declared in this scope
   71 |         c=L[i];
      |         ^
race.cpp:72:9: error: 'g' was not declared in this scope
   72 |         g[u].push_back({v,c});
      |         ^
race.cpp:75:19: error: 'CN' was not declared in this scope; did you mean 'N'?
   75 |     for(int i=0;i<CN;i++){
      |                   ^~
      |                   N
race.cpp:76:9: error: 'dep' was not declared in this scope
   76 |         dep[i]=0;
      |         ^~~
race.cpp:77:9: error: 'dist' was not declared in this scope
   77 |         dist[i]=0;
      |         ^~~~
race.cpp:78:9: error: 'sz' was not declared in this scope
   78 |         sz[i]=0;
      |         ^~
race.cpp:80:5: error: 'dep' was not declared in this scope
   80 |     dep[1]=0;
      |     ^~~
race.cpp:81:5: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   81 |     dfs(1,N);
      |     ^~~
      |     ffs
race.cpp:82:13: error: 'res' was not declared in this scope
   82 |     int ans=res;
      |             ^~~