# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
32138 |
2017-09-27T20:00:55 Z |
imaxblue |
Cities (BOI16_cities) |
C++14 |
|
4000 ms |
236276 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, m, k, a, b, c, N, B;
ll dis[33][100005], D;
bool u[33][100005];
vector<pii> v[100005];
pq<pair<ll, int> > q;
int main(){
scanf("%i%i%i", &n, &k, &m);
fox(l, (1 << k)){
fox1(l2, n) dis[l][l2]=(1LL << 60);
}
fox(l, k){
scanf("%i", &a);
dis[1 << l][a]=0;
q.push(mp(0, (1 << l) + (a << 5)));
}
fox(l, m){
scanf("%i%i%i", &a, &b, &c);
v[a].pb(mp(b, c));
v[b].pb(mp(a, c));
}
while(!q.empty()){
N=(q.top().y >> 5); D=-q.top().x; B=(q.top().y&31); q.pop();
if (u[B][N]) continue;
u[B][N]=1;
//cout << N << ' ' << B << endl;
if (B==(1 << k)-1){
cout << D << endl;
return 0;
}
fox(l, (1 << k)){
if (dis[B|l][N]>D+dis[l][N]){
dis[B|l][N]=D+dis[l][N];
q.push(mp(-D-dis[l][N], (B|l)+(N << 5)));
}
}
fox(l, v[N].size()){
if (dis[B][v[N][l].x]>D+v[N][l].y){
dis[B][v[N][l].x]=D+v[N][l].y;
q.push(mp(-D-v[N][l].y, B+(v[N][l].x << 5)));
}
}
}
return 0;
}
Compilation message
cities.cpp: In function 'int main()':
cities.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
cities.cpp:62:9: note: in expansion of macro 'fox'
fox(l, v[N].size()){
^
cities.cpp:33:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i%i", &n, &k, &m);
^
cities.cpp:38:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &a);
^
cities.cpp:43:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i%i", &a, &b, &c);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
33364 KB |
Output is correct |
2 |
Correct |
0 ms |
33364 KB |
Output is correct |
3 |
Correct |
0 ms |
33364 KB |
Output is correct |
4 |
Correct |
0 ms |
33364 KB |
Output is correct |
5 |
Correct |
0 ms |
33364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
789 ms |
64248 KB |
Output is correct |
2 |
Correct |
656 ms |
51892 KB |
Output is correct |
3 |
Correct |
226 ms |
38108 KB |
Output is correct |
4 |
Correct |
129 ms |
38580 KB |
Output is correct |
5 |
Correct |
353 ms |
45812 KB |
Output is correct |
6 |
Correct |
89 ms |
38172 KB |
Output is correct |
7 |
Correct |
3 ms |
33632 KB |
Output is correct |
8 |
Correct |
3 ms |
33496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
34280 KB |
Output is correct |
2 |
Correct |
6 ms |
33888 KB |
Output is correct |
3 |
Correct |
3 ms |
33636 KB |
Output is correct |
4 |
Correct |
3 ms |
33888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2803 ms |
88820 KB |
Output is correct |
2 |
Correct |
2476 ms |
88740 KB |
Output is correct |
3 |
Correct |
1546 ms |
61148 KB |
Output is correct |
4 |
Correct |
1326 ms |
88328 KB |
Output is correct |
5 |
Correct |
273 ms |
50908 KB |
Output is correct |
6 |
Correct |
119 ms |
40296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4000 ms |
236276 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |