# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
220939 | 2020-04-09T10:01:23 Z | Ruxandra985 | Cities (BOI16_cities) | C++14 | 6000 ms | 165680 KB |
#include <bits/stdc++.h> #define DIMN 100010 #define INF 1000000000000000 using namespace std; long long dist[64][DIMN]; int sp[DIMN] , poz[DIMN]; vector <pair <int,int> > v[DIMN]; priority_queue <pair <long long , pair <int,int> > > h; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , m , k , i , j , x , y , nod , vecin , c , cst , mask , st , big; long long sum = 0 , cost; fscanf (fin,"%d%d%d",&n,&k,&m); for (i = 1 ; i <= k ; i++){ fscanf (fin,"%d",&sp[i]); poz[sp[i]] = i; } for (i = 1 ; i <= m ; i++){ fscanf (fin,"%d%d%d",&x,&y,&c); v[x].push_back(make_pair(y , c)); v[y].push_back(make_pair(x , c)); } for (i = 0 ; i < 32 ; i++){ for (j = 1 ; j <= n ; j++) dist[i][j] = INF; } for (j = 1 ; j <= n ; j++){ if (poz[j]){ dist[1 << (poz[j] - 1)][j] = 0; h.push(make_pair(0 , make_pair(1 << (poz[j] - 1) , j))); } else { dist[0][j] = 0; h.push(make_pair(0 , make_pair(0 , j))); } } while (!h.empty()){ cost = -h.top().first; mask = h.top().second.first; nod = h.top().second.second; h.pop(); if (dist[mask][nod] != cost) continue; /// nu e ok /// acuma trb sa vad cum se pot combina starile for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i].first; cst = v[nod][i].second; big = ((1 << k) - 1) ^ mask; for (st = big ; ; st = (st - 1) & big ){ if (dist[mask | st][vecin] > dist[mask][nod] + cst + dist[st][vecin]){ dist[mask | st][vecin] = dist[mask][nod] + cst + dist[st][vecin]; h.push(make_pair(-dist[mask | st][vecin] , make_pair(mask|st , vecin))); } if (!st) break; } } } sum = INF; for (i = 1 ; i <= n ; i++) sum = min(sum , dist[(1 << k) - 1][i]); fprintf (fout,"%lld",sum); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 2816 KB | Output is correct |
2 | Correct | 6 ms | 2816 KB | Output is correct |
3 | Correct | 6 ms | 2816 KB | Output is correct |
4 | Correct | 7 ms | 2944 KB | Output is correct |
5 | Correct | 6 ms | 2944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1096 ms | 50532 KB | Output is correct |
2 | Correct | 973 ms | 50124 KB | Output is correct |
3 | Correct | 456 ms | 33008 KB | Output is correct |
4 | Correct | 128 ms | 8700 KB | Output is correct |
5 | Correct | 414 ms | 38240 KB | Output is correct |
6 | Correct | 100 ms | 8180 KB | Output is correct |
7 | Correct | 10 ms | 3456 KB | Output is correct |
8 | Correct | 8 ms | 3328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 3840 KB | Output is correct |
2 | Correct | 15 ms | 3840 KB | Output is correct |
3 | Correct | 10 ms | 3328 KB | Output is correct |
4 | Correct | 13 ms | 3712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3310 ms | 99744 KB | Output is correct |
2 | Correct | 3084 ms | 99348 KB | Output is correct |
3 | Correct | 1707 ms | 47440 KB | Output is correct |
4 | Correct | 2069 ms | 54076 KB | Output is correct |
5 | Correct | 468 ms | 26588 KB | Output is correct |
6 | Correct | 194 ms | 11264 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6072 ms | 165680 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |