# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208587 | 2020-03-11T17:42:29 Z | DodgeBallMan | Cities (BOI16_cities) | C++14 | 6000 ms | 235672 KB |
#include <bits/stdc++.h> #define pii pair<long long, long long> #define x first #define y second using namespace std; const int N = 1e5 + 2; vector<pii> g[N]; vector<int> bit[10]; long long d[N][1<<5], ans = 1e18; int n, k, m, id[N]; int main() { memset( id, -1, sizeof id ); fill_n( 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( pii( b, d ) ), g[b].emplace_back( pii( 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, make_pair( 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], make_pair( i, x ) ); } } } while( !q.empty() ) { auto now = q.top(); q.pop(); if( d[now.y.x][now.y.y] != -now.x ) continue; long long di = -now.x; int u = now.y.x, bi = now.y.y; for( pii 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 = 1 ; i <= n ; i++ ) ans = min( ans, d[i][(1<<k)-1] ); printf("%lld",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 28152 KB | Output is correct |
2 | Correct | 17 ms | 28152 KB | Output is correct |
3 | Correct | 18 ms | 28280 KB | Output is correct |
4 | Correct | 18 ms | 28152 KB | Output is correct |
5 | Correct | 17 ms | 28152 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1503 ms | 87932 KB | Output is correct |
2 | Correct | 1491 ms | 87008 KB | Output is correct |
3 | Correct | 1086 ms | 82864 KB | Output is correct |
4 | Correct | 123 ms | 37552 KB | Output is correct |
5 | Correct | 571 ms | 50896 KB | Output is correct |
6 | Correct | 112 ms | 37316 KB | Output is correct |
7 | Correct | 24 ms | 28724 KB | Output is correct |
8 | Correct | 20 ms | 28536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 29700 KB | Output is correct |
2 | Correct | 38 ms | 29816 KB | Output is correct |
3 | Correct | 36 ms | 29612 KB | Output is correct |
4 | Correct | 28 ms | 28992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4639 ms | 137340 KB | Output is correct |
2 | Correct | 4551 ms | 136316 KB | Output is correct |
3 | Correct | 3887 ms | 131960 KB | Output is correct |
4 | Correct | 2281 ms | 112324 KB | Output is correct |
5 | Correct | 459 ms | 57104 KB | Output is correct |
6 | Correct | 137 ms | 40468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6070 ms | 235672 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |