# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
96243 |
2019-02-07T12:46:24 Z |
easrui |
Cities (BOI16_cities) |
C++14 |
|
6000 ms |
39268 KB |
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int MN = 1e5+5;
long long N,K,M,A,B,d,sz,Im[5],cur,tmp,ans,D[32][MN];
bool inQ[MN];
vector<pii> G[MN];
queue<ll> Q;
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> N >> K >> M;
for(int i=0; i<K; i++) cin >> Im[i];
for(int i=0; i<M; i++){
cin >> A >> B >> d;
G[A].push_back(pii(B,d));
G[B].push_back(pii(A,d));
}
sz = 1<<K;
for(int i=0; i<sz; i++)
for(int j=1; j<=N; j++) D[i][j] = 1e18;
for(int j=0; j<K; j++) D[(1<<j)][Im[j]] = 0;
for(int i=1; i<sz; i++){
for(int j=1; j<=N; j++){
tmp = 1e18;
for(int p=1; p<sz; p++){
if((p&i)!=p) continue;
tmp = min(tmp,D[i-p][j] + D[p][j]);
}
D[i][j] = min(D[i][j],tmp);
}
for(int j=1; j<=N; j++){
Q.push(j);
inQ[j] = true;
}
while(!Q.empty()){
cur = Q.front();
Q.pop();
for(pii x : G[cur]){
if(D[i][x.va] > D[i][cur] + x.vb){
D[i][x.va] = D[i][cur] + x.vb;
if(!inQ[x.va]){
inQ[x.va] = true;
Q.push(x.va);
}
}
}
inQ[cur] = false;
}
}
ans = 1e18;
for(int j=1; j<=N; j++) ans = min(ans,D[sz-1][j]);
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
3 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2808 KB |
Output is correct |
4 |
Correct |
4 ms |
2808 KB |
Output is correct |
5 |
Correct |
3 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
359 ms |
20272 KB |
Output is correct |
2 |
Correct |
287 ms |
19524 KB |
Output is correct |
3 |
Execution timed out |
6103 ms |
15280 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3064 KB |
Output is correct |
2 |
Correct |
6 ms |
3064 KB |
Output is correct |
3 |
Correct |
11 ms |
2936 KB |
Output is correct |
4 |
Correct |
6 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
692 ms |
26648 KB |
Output is correct |
2 |
Correct |
430 ms |
25712 KB |
Output is correct |
3 |
Execution timed out |
6033 ms |
21640 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1145 ms |
39064 KB |
Output is correct |
2 |
Correct |
1712 ms |
39268 KB |
Output is correct |
3 |
Correct |
995 ms |
38376 KB |
Output is correct |
4 |
Execution timed out |
6030 ms |
34104 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |