답안 #56758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56758 2018-07-12T12:20:11 Z wjoao Cities (BOI16_cities) C++11
0 / 100
381 ms 29236 KB
#include<bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f3f3f3f3f

using namespace std;

long long n, m, k, a, b, c, dist[maxn], ini;
bool is_important[maxn];
vector< pair<long long, long long> > g[maxn];

int main(){
    scanf(" %lld %lld %lld", &n, &k, &m);

    for(long long i = 0; i < k; i++){
        scanf(" %lld", &a);
        if( i == 0 ) ini = a;
        is_important[a] = true;
    }

    for(long long i = 0; i < m; i++){
        scanf(" %lld %lld %lld", &a, &b, &c);
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }

    memset(dist, inf, sizeof dist);

    priority_queue< pair<long long, long long>, vector< pair<long long, long long> >, greater< pair<long long, long long> > > fp;
    long long res = 0;
    dist[ini] = 0;
    fp.push({0, ini});
    while(!fp.empty()){
        long long d = fp.top().first;
        long long v = fp.top().second;
        fp.pop();
        if(dist[v] < d ) continue;
        if(is_important[v]) {
            res += dist[v];
            dist[v] = 0;
        }

        for(long long i = 0; i < g[v].size(); i++){
            long long u = g[v][i].first;
            long long d2 = g[v][i].second;

            if( dist[v] + d2 < dist[u] ){
                dist[u] = dist[v] + d2;
                fp.push({dist[u], u});
            }
        }
    }

    printf("%lld\n", res);
    return 0;
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:26:34: warning: overflow in implicit constant conversion [-Woverflow]
     memset(dist, inf, sizeof dist);
                                  ^
cities.cpp:42:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(long long i = 0; i < g[v].size(); i++){
                              ~~^~~~~~~~~~~~~
cities.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %lld %lld %lld", &n, &k, &m);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %lld", &a);
         ~~~~~^~~~~~~~~~~~~
cities.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %lld %lld %lld", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3448 KB Output is correct
2 Correct 6 ms 3560 KB Output is correct
3 Incorrect 6 ms 3672 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 335 ms 20592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 20592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 328 ms 24876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 29236 KB Output isn't correct
2 Halted 0 ms 0 KB -