답안 #208577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208577 2020-03-11T17:29:07 Z DodgeBallMan Cities (BOI16_cities) C++14
74 / 100
6000 ms 170012 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define pil pair<int, long long>
#define x first
#define y second

using namespace std;

const int N = 1e5 + 10;
vector<pil> g[N];
vector<int> bit[10];
long long d[N][1<<5], ans = 1e18;
int n, k, m, id[N];
int main()
{
    fill( id, id+N, -1 );
    fill( d[0], d[0]+N*(1<<5), ans );
    scanf("%d %d %d",&n,&k,&m);
    for( int i = 0, a ; i < k ; i++ ) {
        scanf("%d",&a);
        id[a] = i;
    }
    for( int i = 0, a, b ; i < m ; i++ ) {
        long long d;
        scanf("%d %d %lld",&a,&b,&d);
        g[a].emplace_back( pil( b, d ) ), g[b].emplace_back( pil( a, d ));
    }
    for( int i = 1 ; i < ( 1 << k ) ; i++ ){
        bit[__builtin_popcount( i )].emplace_back( i );
    }
    for( int b = 1 ; b <= k ; b++ ) {
        priority_queue<pair<long long, pii>> q;
        if( b == 1 ) {
            for( int i = 1 ; i <= n ; i++ ) if( id[i] != -1 ) q.emplace( d[i][(1<<id[i])] = 0, pii( i, (1<<id[i] ) ) );
        }
        else {
            for( int i = 1 ; i <= n ; i++ ) for( int x : bit[b] ) {
                for( int j = 0 ; j < ( 1 << k ) ; j++ ) {
                    if( ( x & j ) != j ) continue ;
                    d[i][x] = min( d[i][x], d[i][j] + d[i][x^j] );
                    q.emplace( -1*d[i][x], pii( i, x ) );
                }
            }
        }
        while( !q.empty() ) {
            long long di = -1*q.top().x;
            int u = q.top().y.x, bi = q.top().y.y;
            q.pop();
            if( d[u][bi] != di ) continue ;
            for( pil v : g[u] ) if( d[v.x][bi] > di + v.y ) {
                d[v.x][bi] = di + v.y;
                q.emplace( -1*d[v.x][bi], pii( v.x, bi ) );
            }
        }
    }
    for( int i = 0 ; i < n ; i++ ) ans = min( ans, d[i][(1<<k)-1] );
    printf("%lld",ans);
    return 0;
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&k,&m);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
cities.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a);
         ~~~~~^~~~~~~~~
cities.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %lld",&a,&b,&d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 28152 KB Output is correct
2 Correct 18 ms 28152 KB Output is correct
3 Correct 17 ms 28152 KB Output is correct
4 Correct 17 ms 28152 KB Output is correct
5 Correct 19 ms 28152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1340 ms 71492 KB Output is correct
2 Correct 1385 ms 70532 KB Output is correct
3 Correct 994 ms 66480 KB Output is correct
4 Correct 119 ms 37360 KB Output is correct
5 Correct 511 ms 46916 KB Output is correct
6 Correct 112 ms 37240 KB Output is correct
7 Correct 24 ms 28536 KB Output is correct
8 Correct 22 ms 28408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 29276 KB Output is correct
2 Correct 35 ms 29264 KB Output is correct
3 Correct 35 ms 29292 KB Output is correct
4 Correct 28 ms 28712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4014 ms 104536 KB Output is correct
2 Correct 3907 ms 103536 KB Output is correct
3 Correct 3377 ms 99132 KB Output is correct
4 Correct 2021 ms 87976 KB Output is correct
5 Correct 439 ms 50680 KB Output is correct
6 Correct 143 ms 39924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6078 ms 170012 KB Time limit exceeded
2 Halted 0 ms 0 KB -