답안 #1090114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090114 2024-09-17T18:02:33 Z LilPluton 경주 (Race) (IOI11_race) C++14
컴파일 오류
0 ms 0 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 5;
vector<vector<pair<int,int>>>adj(sz);
int n, res;
vector<long long> dist(sz), dep(sz, 0);
const int sz = 2e5 + 5;
vector<vector<pair<int, int>>> adj(sz);

int dij(int s, int need, int n) {
    vector<long long> dist(n, LLONG_MAX);
    vector<long long> dep(n, LLONG_MAX);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
    
    dist[s] = 0;
    dep[s] = 0;
    q.push({0, s});
    
    while (!q.empty()) {
        int v = q.top().second;
        long long d_v = q.top().first;
        q.pop();
        
        if (d_v != dist[v]) {
            continue;
        }
        
        if (dist[v] == need) {
            return dep[v];
        }
        
        for (auto i : adj[v]) {
            int u = i.first;
            int weight = i.second;
            
            if (dist[u] > dist[v] + weight) {
                dist[u] = dist[v] + weight;
                dep[u] = dep[v] + 1;
                q.push({dist[u], u});
            }
        }
    }
    
    return LLONG_MAX;
}

int best_path(int N, int K, int H[][2], int L[]) {
    if (K == 1) {
        return 0;
    }
    
    for (int i = 0; i < N; ++i) {
        adj[H[i][0]].push_back({H[i][1], L[i]});
        adj[H[i][1]].push_back({H[i][0], L[i]});
    }
    
    int res = LLONG_MAX;
    
    for (int i = 0; i < N; ++i) {
        int path_length = dij(i, K, N);
        res = min(res, path_length);
    }
    
    return (res == LLONG_MAX ? -1 : res);
}

Compilation message

race.cpp:8:11: error: redefinition of 'const int sz'
    8 | const int sz = 2e5 + 5;
      |           ^~
race.cpp:4:11: note: 'const int sz' previously defined here
    4 | const int sz = 2e5 + 5;
      |           ^~
race.cpp:9:32: error: redefinition of 'std::vector<std::vector<std::pair<int, int> > > adj'
    9 | vector<vector<pair<int, int>>> adj(sz);
      |                                ^~~
race.cpp:5:30: note: 'std::vector<std::vector<std::pair<int, int> > > adj' previously declared here
    5 | vector<vector<pair<int,int>>>adj(sz);
      |                              ^~~
race.cpp: In function 'int dij(int, int, int)':
race.cpp:45:12: warning: overflow in conversion from 'long long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
   45 |     return LLONG_MAX;
      |            ^~~~~~~~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:58:15: warning: overflow in conversion from 'long long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
   58 |     int res = LLONG_MAX;
      |               ^~~~~~~~~