# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
56209 |
2018-07-10T09:01:58 Z |
윤교준(#1582) |
Cities (BOI16_cities) |
C++11 |
|
6000 ms |
172468 KB |
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
static unsigned char str[22000022], *p=str;
void fg(vector<pii> G[], int a, int b, int c) { G[a].eb(b, c); G[b].eb(a, c); }
const int MAXN = 100005;
const int MAXM = 200005;
vector<int> KV[1<<5];
priority_queue<pli, vector<pli>, greater<pli>> PQ;
vector<pii> G[MAXN];
ll dp[MAXN][1<<5];
int A[MAXM], B[MAXM], C[MAXM];
int D[MAXN];
ll Ans = INFLL;
int N, M, K;
int main() {
fread(str, 1, 22000022, stdin);
rf(N) rf(K) rf(M)
for(int i = 1, c; i <= K; i++) {
rf(c)
D[c] = i;
}
for(int i = 1; i <= M; i++) {
rf(A[i]) rf(B[i]) rf(C[i])
fg(G, A[i], B[i], C[i]);
}
for(int i = 1; i <= N; i++)
fill(dp[i]+1, dp[i]+(1<<K), INFLL);
for(int i = 1; i <= N; i++) {
//PQ.push(pli(0, i<<5));
if(D[i]) {
dp[i][1<<(D[i]-1)] = 0;
PQ.push(pli(0, (i<<5) | (1<<(D[i]-1))));
}
}
for(int i = 0; i < (1<<K); i++)
for(int j = 0; j < (1<<K); j++)
if((j&i) == i)
KV[i].pb(j);
for(; !PQ.empty();) {
ll dst; int idx, key;
tie(dst, idx) = PQ.top(); PQ.pop();
key = idx & 31; idx >>= 5;
if(dp[idx][key] < dst) continue;
for(auto &e : G[idx]) {
int nidx = e.first;
ll ndst = dst + e.second;
for(int nkey : KV[key]) {
ll t = ndst + dp[nidx][nkey^key];
if(dp[nidx][nkey] <= t) continue;
dp[nidx][nkey] = t;
PQ.push(pli(t, (nidx<<5) | nkey));
}
}
}
for(int i = 1; i <= N; i++)
upmin(Ans, dp[i][(1<<K)-1]);
cout << Ans << endl;
return 0;
}
Compilation message
cities.cpp: In function 'int main()':
cities.cpp:41:7: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
fread(str, 1, 22000022, stdin);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2824 KB |
Output is correct |
3 |
Correct |
3 ms |
2848 KB |
Output is correct |
4 |
Correct |
4 ms |
2920 KB |
Output is correct |
5 |
Correct |
5 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1588 ms |
57284 KB |
Output is correct |
2 |
Correct |
1166 ms |
57284 KB |
Output is correct |
3 |
Correct |
576 ms |
57284 KB |
Output is correct |
4 |
Correct |
69 ms |
57284 KB |
Output is correct |
5 |
Correct |
453 ms |
57284 KB |
Output is correct |
6 |
Correct |
48 ms |
57284 KB |
Output is correct |
7 |
Correct |
8 ms |
57284 KB |
Output is correct |
8 |
Correct |
5 ms |
57284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
57284 KB |
Output is correct |
2 |
Correct |
13 ms |
57284 KB |
Output is correct |
3 |
Correct |
11 ms |
57284 KB |
Output is correct |
4 |
Correct |
11 ms |
57284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3564 ms |
106692 KB |
Output is correct |
2 |
Correct |
4113 ms |
106692 KB |
Output is correct |
3 |
Correct |
2362 ms |
106692 KB |
Output is correct |
4 |
Correct |
2140 ms |
106692 KB |
Output is correct |
5 |
Correct |
461 ms |
106692 KB |
Output is correct |
6 |
Correct |
150 ms |
106692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6059 ms |
172468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |