#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
#define DEBUG 0
bool spec[maxn];
vpi adj[maxn];
vi adj2[maxn];
ll dist0[maxn], distK[maxn];
int cnt[maxn];
int N;
bool ok(int X){
FOR(i,0,N-1) adj2[i].clear();
FOR(i,0,N-1){
aFOR(j, adj[i]) if (i < j.f){
if (dist0[i] + j.s + distK[j.f] <= X && dist0[j.f] + j.s + distK[i] <= X){
adj2[i].pb(j.f); adj2[j.f].pb(i);
}
}
}
vi v;
FOR(i,0,N-1){
cnt[i] = 0;
aFOR(j, adj2[i]) if (spec[j]) cnt[i]++;
if (cnt[i] >= 2) v.pb(i);
}
while (!v.empty()){
int x = v.back(); v.pop_back();
if (x == 0) return 1;
aFOR(i, adj2[x]){
cnt[i]++; if (cnt[i] == 2) v.pb(i);
}
}
return 0;
}
int32_t travel_plan(int32_t N, int32_t M, int32_t R[][2], int32_t L[], int32_t K, int32_t P[])
{
::N = N;
FOR(i,0,M-1){
adj[R[i][0]].pb(pi(R[i][1], L[i]));
adj[R[i][1]].pb(pi(R[i][0], L[i]));
}
FOR(i,0,K-1) spec[P[i]] = 1;
// dijkstra from 0
priority_queue <pi,vector <pi>, greater <pi> > pq;
mem(dist0,-1);
pq.push(pi(0,0)); dist0[0] = 0;
while (!pq.empty()){
pi cur = pq.top(); pq.pop();
if (dist0[cur.s] != cur.f) continue;
aFOR(i, adj[cur.s]){
if (dist0[i.f] == -1 || dist0[i.f] > cur.f + i.s){
dist0[i.f] = cur.f + i.s;
pq.push({dist0[i.f], i.f});
}
}
}
// multisource dijkstra from exits
mem(distK,-1);
FOR(i,0,K-1){
pq.push(pi(0, P[i])); distK[P[i]] = 0;
}
while (!pq.empty()){
pi cur = pq.top(); pq.pop();
if (distK[cur.s] != cur.f) continue;
aFOR(i, adj[cur.s]){
if (distK[i.f] == -1 || distK[i.f] > cur.f + i.s){
distK[i.f] = cur.f + i.s;
pq.push({distK[i.f], i.f});
}
}
}
if (DEBUG){
FOR(i,0,N-1) cout << dist0[i] << ' ';
cout << '\n';
FOR(i,0,N-1) cout << distK[i] << ' ';
cout << '\n';
}
ll l = -1, r = 1e18;
while (l + 1 < r){
ll m = (l + r) >> 1;
if (ok(m)) r = m;
else l = m;
}
return r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
12756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |