# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599296 |
2022-07-19T12:28:19 Z |
nguyentu |
Cities (BOI16_cities) |
C++14 |
|
6000 ms |
240468 KB |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ii pair<int , int>
#define iv pair<ii , ii>
#define iii pair<int , ii>
#define fi first
#define se second
#define int long long
const int inf = 1e18 + 7;
const int MAX_N = 1e5 + 7;
const int MOD = 1e9 + 7;
int n , m , k;
vector<ii> adj[MAX_N];
int f[MAX_N][(1 << 5) + 1];
int a[MAX_N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin >> n >> k >> m;
for (int i = 1 ; i <= n ;i ++) {
for (int j = 1 ; j < (1 << k) ; j++) {
f[i][j] = inf;
}
}
priority_queue<iii , vector<iii> , greater<iii>> pq;
for (int i = 0 ; i < k ; i++) {
cin >> a[i];
f[a[i]][1 << i] = 0;
pq.push(iii(0 , ii(a[i] , 1 << i)));
}
for (int i = 1 ; i <= m ; i++) {
int u , v , w; cin >> u >> v >> w;
adj[u].push_back(ii(v , w));
adj[v].push_back(ii(u , w));
}
while (!pq.empty()) {
int u = pq.top().se.fi;
int mask1 = pq.top().se.se;
pq.pop();
for (auto edge : adj[u]) {
int v , w;
tie(v , w) = edge;
for (int mask2 = 0 ; mask2 < (1 << k) ; mask2++) {
if (!(mask1 & mask2) && (f[u][mask1] + f[v][mask2] + w) < f[v][mask1|mask2]) {
f[v][mask1|mask2] = f[u][mask1] + f[v][mask2] + w;
pq.push(iii(f[v][mask1|mask2] , ii(v , mask1|mask2)));
}
// if (!(mask1 & mask2) && (f[u][mask1] + f[v][mask2] + w) < f[u][mask1|mask2]) {
// f[u][mask1|mask2] = f[u][mask1] + f[v][mask2] + w;
// pq.push(iii(f[u][mask1|mask2] , ii(u , mask1|mask2)));
// }
}
}
}
int ans = inf;
for (int i = 1 ; i <= n ; i++) {
ans = min(ans , f[i][(1 << k) - 1]);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2676 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2676 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1361 ms |
63988 KB |
Output is correct |
2 |
Correct |
1178 ms |
63400 KB |
Output is correct |
3 |
Correct |
513 ms |
40508 KB |
Output is correct |
4 |
Correct |
308 ms |
13916 KB |
Output is correct |
5 |
Correct |
440 ms |
45580 KB |
Output is correct |
6 |
Correct |
108 ms |
13140 KB |
Output is correct |
7 |
Correct |
6 ms |
3348 KB |
Output is correct |
8 |
Correct |
3 ms |
3132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3920 KB |
Output is correct |
2 |
Correct |
17 ms |
3924 KB |
Output is correct |
3 |
Correct |
8 ms |
3476 KB |
Output is correct |
4 |
Correct |
11 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4467 ms |
137944 KB |
Output is correct |
2 |
Correct |
4484 ms |
137124 KB |
Output is correct |
3 |
Correct |
2009 ms |
59124 KB |
Output is correct |
4 |
Correct |
4072 ms |
75944 KB |
Output is correct |
5 |
Correct |
1344 ms |
42876 KB |
Output is correct |
6 |
Correct |
1152 ms |
20616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6057 ms |
240468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |