# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
453271 |
2021-08-04T10:25:05 Z |
Vladth11 |
Cities (BOI16_cities) |
C++14 |
|
2683 ms |
49652 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define debugs(x) cerr << #x << " " << x << " "
//#include"holiday.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 666013;
const ll BLOCK = 225;
const ll base = 31;
const ll nr_of_bits = 21;
vector <pii> v[NMAX];
ll n, k, m;
struct ura {
ll a, b, c;
};
vector <ura> edges;
ll scor = 0;
ll viz[NMAX];
bool cmp(ura a, ura b) {
return a.c < b.c;
}
void add_Edge(ll a, ll b, ll c) {
edges.push_back({a, b, c});
}
ll d[NMAX][6];
ll dp[(1 << 6)][NMAX];
ll imp[NMAX];
ll special[NMAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> m;
for(ll i = 1; i <= k; i++) {
ll x;
cin >> x;
special[x] = i;
imp[i - 1] = x;
}
for(ll i = 1; i <= m; i++) {
ll a, b, c;
cin >> a >> b >> c;
v[a].push_back({b, c});
v[b].push_back({a, c});
}
for(ll mask = 0; mask < (1 << k); mask++) {
for(ll i = 0; i <= n; i++)
dp[mask][i] = HALF;
}
for(ll i = 1; i <= k; i++) {
dp[(1 << (i - 1))][imp[i - 1]] = 0;
}
for(ll i = 1; i <= n; i++)
dp[0][i] = 0;
for(ll mask = 0; mask < (1 << k); mask++) {
for(ll i = 1; i <= n; i++) {
for(ll submask = mask; submask > 0; submask = (submask - 1) & mask) {
if(special[i]) {
if(!(mask & (1 << (special[i] - 1))))
continue;
}
ll newmask = (mask ^ submask);
if(special[i]) {
newmask ^= (1 << (special[i] - 1));
}
dp[mask][i] = min(dp[mask][i], dp[submask][i] + dp[newmask][i]);
}
}
priority_queue <pii> pq;
for(ll i = 0; i <= n; i++) {
viz[i] = 0;
if(special[i]) {
if(!(mask & (1 << (special[i] - 1))))
continue;
}
pq.push({-dp[mask][i], i});
}
while(pq.size()) {
pii node = pq.top();
ll city = node.second;
pq.pop();
if(viz[city])
continue;
viz[city] = 1;
for(auto x : v[city]) {
int i = x.first;
if(special[i]) {
if(!(mask & (1 << (special[i] - 1))))
continue;
}
if(dp[mask][city] + x.second < dp[mask][x.first]) {
dp[mask][x.first] = dp[mask][city] + x.second;
pq.push({-dp[mask][x.first], x.first});
}
}
}
}
ll sol = INF;
for(ll i = 1; i <= n; i++) {
sol = min(sol, dp[(1 << k) - 1][i]);
}
cout << sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2668 KB |
Output is correct |
5 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
718 ms |
30804 KB |
Output is correct |
2 |
Correct |
695 ms |
30488 KB |
Output is correct |
3 |
Correct |
463 ms |
20756 KB |
Output is correct |
4 |
Correct |
85 ms |
15340 KB |
Output is correct |
5 |
Correct |
411 ms |
27840 KB |
Output is correct |
6 |
Correct |
82 ms |
15172 KB |
Output is correct |
7 |
Correct |
5 ms |
2892 KB |
Output is correct |
8 |
Correct |
5 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3020 KB |
Output is correct |
2 |
Correct |
8 ms |
3020 KB |
Output is correct |
3 |
Incorrect |
5 ms |
2892 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1410 ms |
37160 KB |
Output is correct |
2 |
Correct |
1354 ms |
36628 KB |
Output is correct |
3 |
Correct |
891 ms |
26984 KB |
Output is correct |
4 |
Correct |
739 ms |
27968 KB |
Output is correct |
5 |
Correct |
196 ms |
18416 KB |
Output is correct |
6 |
Incorrect |
100 ms |
17536 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2646 ms |
49652 KB |
Output is correct |
2 |
Correct |
2683 ms |
49620 KB |
Output is correct |
3 |
Correct |
2671 ms |
49312 KB |
Output is correct |
4 |
Correct |
1773 ms |
39700 KB |
Output is correct |
5 |
Correct |
1334 ms |
34232 KB |
Output is correct |
6 |
Correct |
306 ms |
19904 KB |
Output is correct |
7 |
Correct |
110 ms |
17956 KB |
Output is correct |