Submission #919243

#TimeUsernameProblemLanguageResultExecution timeMemory
919243djs100201Cyberland (APIO23_cyberland)C++17
0 / 100
3180 ms2097152 KiB
#include "cyberland.h" #include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx2") #define all(v) v.begin(),v.end() using namespace std; using ll = long long; using P = pair<ll, ll>; using PP = pair<ll, P>; const ll n_ =1e5+100, inf = (ll)2e9 * (ll)1e9 + 7, mod = 1e9+7; ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k; ll gcd(ll x,ll y){ if(!y)return x; return gcd(y,x%y); } vector<P>v[n_]; long double dist[n_][61],pw[n_]; ll par[n_],par2[n_]; ll find(ll x){ if(par[x]<0)return x; return par[x]=find(par[x]); } void merge(ll x,ll y){ x=find(x),y=find(y); if(x==y)return; par[x]=y; } ll find2(ll x){ if(par2[x]<0)return x; return par2[x]=find2(par2[x]); } void merge2(ll x,ll y){ x=find2(x),y=find2(y); if(x==y)return; par2[x]=y; } double solve(int N, int M, int K, int H, vector<int> U, vector<int> V, vector<int> C, vector<int> arr) { n=N,m=M,k=min(60,K); for(int i=0;i<N;i++){ par[i]=-1; for(int j=0;j<=k;j++)dist[i][j]=inf; } pw[0]=1; for(int i=1;i<=k;i++)pw[i]=pw[i-1]*2; for(int i=0;i<M;i++){ merge(U[i],V[i]); v[U[i]].push_back({V[i],C[i]}); v[V[i]].push_back({U[i],C[i]}); if(U[i]!=H && V[i]!=H)merge2(U[i],V[i]); } if(find(0)!=find(H))return -1; priority_queue<pair<long double,P>,vector<pair<long double,P>>,greater<>>pq; pq.push({0.0,{H,0}}); dist[H][0]=0.0; double ans=inf; while(pq.size()){ double a=pq.top().first; b=pq.top().second.first,c=pq.top().second.second; pq.pop(); //cout<<a<<' '<<b<<' '<<c<<endl; if(dist[b][c]<a)continue; if(b==0){ ans=min(ans,a); continue; } for(auto nxt:v[b]){ if(find2(nxt.first)!=find2(0))continue; double cost=a+nxt.second/pw[c]; if(arr[nxt.first]==0){ if(find(nxt.first)==find(0))ans=min(ans,cost); } else if(arr[nxt.first]==1 || c==k){ if(cost<dist[nxt.first][c]){ dist[nxt.first][c]=cost; pq.push({cost,{nxt.first,c}}); } } else{ if(cost<dist[nxt.first][c]){ dist[nxt.first][c]=cost; pq.push({cost,{nxt.first,c}}); } if(cost<dist[nxt.first][c+1]){ dist[nxt.first][c+1]=cost; pq.push({cost,{nxt.first,c+1}}); } } } } if(ans>=inf-10)return -1; else return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...