Submission #968408

#TimeUsernameProblemLanguageResultExecution timeMemory
968408Batorgil952Cyberland (APIO23_cyberland)C++17
97 / 100
3010 ms98888 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #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< int, int > >, vector< pair< double, pair< int, int > > >, greater< pair< double, pair< int, int > > > > 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) { K=min(K, 70); for(int i=0; i<N; i++){ v[i].clear(); for(int j=0; j<=K; 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; } 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 j=0; j<=K; j++){ T[i][j]=0; } } } for(int i=0; i<=K; 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]){ 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 && z+1<=K){ 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))); } } } } double ans=T[H][0]; for(int i=1; i<=K; i++){ ans=min(ans, T[H][i]); } return ans; }

Compilation message (stderr)

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:77:10: warning: unused variable 'ze' [-Wunused-variable]
   77 |   double ze=0.0;
      |          ^~
#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...