This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <vector>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <cassert>
#include <list>
using namespace std;
#define all(x) x.begin(), x.end()
#define rll(x) x.rbegin(), x.rend()
#define comp(x) x.erase(unique(all(x)), x.end())
#define MOD 1000000007
#define MOD2 998244353
#define debug(x) cout << #x<<" is "<<x<<"\n";
#define X first
#define Y second
#define DEB cout<<"[DEBUG]"
#define PAIR(a,b) "("<<a<<", "<<b<<")"
#define PRINT1(V) DEB<<#V<<endl; for(auto i : V)DEB<<i<<"\n"
#define PRINT2(V) DEB<<#V<<endl; for(auto [a,b] : V)DEB<<PAIR(a,b)<<"\n";
typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef pair<ld,ll> Pd;
vector<P> adj[202020];
ld dist[202020][77];
ll p[202020];
ll find(ll x){
if(p[x]<0)return x;
return p[x] = find(p[x]);
}
void merge(ll x, ll y){
x = find(x), y = find(y);
if(x==y)return;
p[y]=x;
}
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
K = min<ll>(K,70);
for(int i = 0 ; i < N ; i++){
for(int j = 0 ; j <= K ; j++)dist[i][j] = 1e15;
adj[i].clear();
p[i]=-1;
}
for(int i = 0 ; i < M ; i++){
if(x[i] != H and y[i] != H)merge(x[i],y[i]);
adj[x[i]].push_back({y[i],c[i]});
adj[y[i]].push_back({x[i],c[i]});
}
priority_queue<Pd,vector<Pd>,greater<Pd>> pq[33];
for(int i = 0 ; i < N ; i++)if(arr[i]==0 and find(0) == find(i)){
for(int j = 0 ; j <= K ; j++)dist[i][j]=0, pq[j].push({0,i});
}
ld ret = 1e15;
pq[0].push({0,0});
dist[0][0] = 0;
for(int i = 0 ; i <= K ; i++){
while(pq[i].size()){
auto [d,cur] = pq[i].top(); pq[i].pop();
if(cur==H or dist[cur][i] < d)continue;
for(auto [next,w] : adj[cur]){
if(dist[next][i] > d+w){
dist[next][i] = d+w;
pq[i].push({d+w,next});
}
if(arr[next]==2 and i<K and dist[next][i+1] > (d+w)/2.0){
dist[next][i+1] = (d+w)/2.0;
pq[i+1].push({(d+w)/2.0,next});
}
}
}
ret = min(ret, dist[H][i]);
}
if(ret==1e15)return -1;
return (double)ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |