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 "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
const int TAILLEMAXI=100*1000+2,DIVMAXI=32;
int dejavu[TAILLEMAXI];
int deja[TAILLEMAXI][DIVMAXI];
vector<int> pv;
int zero[TAILLEMAXI];
vector<pair<int,int>> adja[TAILLEMAXI];
set<tuple<double,int,int>> encours;
set<tuple<double,int,int>>::iterator it;
int pos,nbdiv2,arrive;
double dist;
void dfs(int n){
if (n==arrive){
dejavu[n]=1;
return ;
}
if (dejavu[n]==1){
return ;
}
if (pv[n]==0){
zero[n]=1;
}
dejavu[n]=1;
for (int i=0;i<(int)adja[n].size();i++){
dfs(adja[n][i].first);
}
}
double solve(int nbnoeuds, int nbarretes, int K, int H,vector<int> deb,vector<int> fin,vector<int> temps,vector<int> arr) {
for (int i=0;i<TAILLEMAXI;i++){
adja[i].clear();
zero[i]=0;
dejavu[i]=0;
}
encours.clear();
pv.clear();
pv=arr;
arrive=H;
K=min(K,DIVMAXI-1);
for (int i=0;i<nbarretes;i++){
adja[deb[i]].push_back(make_pair(fin[i],temps[i]));
adja[fin[i]].push_back(make_pair(deb[i],temps[i]));
}
dfs(0);
zero[0]=1;
encours.insert(make_tuple(0,arrive,0));
for (int i=0;i<TAILLEMAXI;i++){
for (int j=0;j<DIVMAXI;j++){
deja[i][j]=-1;
}
}
while (encours.size()!=0){
it=encours.begin();
dist=get<0>(*(it));
pos=get<1>(*(it));
nbdiv2=get<2>(*(it));
encours.erase(it);
if (deja[pos][nbdiv2]==-1){
if (zero[pos]==1){
return dist;
}
deja[pos][nbdiv2]=dist;
if (arr[pos]==2 and nbdiv2<K){
for (int ivois=0;ivois<(int)adja[pos].size();ivois++){
if (deja[adja[pos][ivois].first][nbdiv2+1]==-1){
encours.insert(make_tuple(dist+(double)adja[pos][ivois].second*(double)pow(0.5,(nbdiv2+1)),adja[pos][ivois].first,nbdiv2+1));
}
if (deja[adja[pos][ivois].first][nbdiv2]==-1){
encours.insert(make_tuple(dist+(double)adja[pos][ivois].second*(double)pow(0.5,(nbdiv2)),adja[pos][ivois].first,nbdiv2));
}
}
}
else {
for (int ivois=0;ivois<(int)adja[pos].size();ivois++){
if (deja[adja[pos][ivois].first][nbdiv2]==-1){
encours.insert(make_tuple(dist+(double)adja[pos][ivois].second*(double)pow(0.5,(nbdiv2)),adja[pos][ivois].first,nbdiv2));
}
}
}
}
}
return -1;
}
# | 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... |