Submission #968391

#TimeUsernameProblemLanguageResultExecution timeMemory
968391Batorgil952Cyberland (APIO23_cyberland)C++17
97 / 100
3032 ms130320 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define ff first #define ss second using namespace std; const int N=1e5+5; vector< pair< int, int > > v[N]; double T[N][72]; bool B[N]; priority_queue< pair< double, pair< ll, ll > >, vector< pair< double, pair< ll, ll > > >, greater< pair< double, pair< ll, ll > > > > q; int DFS(int p, int g){ if(p==g) return 1; int vn=v[p].size(); int s=0; for(int i=0; i<vn; i++){ if(!B[v[p][i].ff]){ B[v[p][i].ff]=true; s=max(s, DFS(v[p][i].ff, g)); } } return s; } 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) { for(int i=0; i<N; i++){ v[i].clear(); for(int j=0; j<=70; j++){ T[i][j]=1000000000000000000.0; } B[i]=false; } for(int i=0; i<M; i++){ v[x[i]].pb(mp(y[i], c[i])); v[y[i]].pb(mp(x[i], c[i])); } B[0]=true; if(DFS(0, H)==0){ return -1; } K=min(K, 70); q.push(mp(0, mp(0, 0))); for(int i=1; i<N; i++){ if(B[i] && arr[i]==0){ q.push(mp(0, mp(i, 0))); } } for(int i=0; i<=70; i++){ T[0][i]=0; } while(!q.empty()){ int x=q.top().ss.ff; int z=q.top().ss.ss; double y=q.top().ff; q.pop(); if(x==H){ continue; } if(y>T[x][z] || z>K){ continue; } int vn=v[x].size(); double ze=0.0; for(int i=0; i<vn; i++){ if(arr[v[x][i].ff]==1){ if(T[v[x][i].ff][z]>T[x][z]+v[x][i].ss*1.0){ T[v[x][i].ff][z]=T[x][z]+v[x][i].ss*1.0; q.push(mp(T[v[x][i].ff][z], mp(v[x][i].ff, z))); } } if(arr[v[x][i].ff]==2){ if(T[v[x][i].ff][z+1]>(T[x][z]+v[x][i].ss*1.0)/2.0){ T[v[x][i].ff][z+1]=(T[x][z]+v[x][i].ss*1.0)/2.0; q.push(mp(T[v[x][i].ff][z+1], mp(v[x][i].ff, z+1))); } if(T[v[x][i].ff][z]>T[x][z]+v[x][i].ss*1.0){ T[v[x][i].ff][z]=T[x][z]+v[x][i].ss*1.0; q.push(mp(T[v[x][i].ff][z], mp(v[x][i].ff, z))); } } if(arr[v[x][i].ff]==0){ if(T[v[x][i].ff][z]>ze){ T[v[x][i].ff][z]=ze; q.push(mp(T[v[x][i].ff][z], mp(v[x][i].ff, z))); } } } } double ans=T[H][0]; for(int i=1; i<=K; i++){ ans=min(ans, T[H][i]); } 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...