#include "cyberland.h"
#include <vector>
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
typedef long long ll;
const double MAX_DIST=1000000000000000000.0;
using namespace std;
int n,m,k,h;
vector<pair<int,double>>nodes[100000];
double dist[100000];
bool vis[100000];
void dfs(int node){
if(vis[node])
return;
vis[node]=true;
if(node==h)
return;
for(pair<int,double>ne:nodes[node]){
dfs(ne.first);
}
}
double solve(int N,int M,int K,int H,vector<int>x,vector<int>y,vector<int>c,vector<int>arr){
n=N;
m=M;
k=K;
h=H;
for(int i=0;i<n;i++){
nodes[i].clear();
dist[i]=MAX_DIST;
vis[i]=false;
}
for(int i=0;i<m;i++){
nodes[x[i]].emplace_back(y[i],c[i]);
nodes[y[i]].emplace_back(x[i],c[i]);
}
dfs(0);
dist[0]=0;
queue<int>q;
q.push(0);
if(!vis[h])
return -1;
for(int i=0;i<n;i++){
if(arr[i]==0&&vis[i]){
dist[i]=0;
q.push(i);
}
}
while(!q.empty()){
int curr=q.front();
q.pop();
if(curr==h)
continue;
for(pair<int,double>ne:nodes[curr]){
double new_dist=dist[curr]+ne.second;
if(new_dist<dist[ne.first]){
dist[ne.first]=new_dist;
q.push(ne.first);
}
}
}
k=min(100,k);
while(k--){
for(int i=0;i<n;i++){
if(arr[i]==2&&vis[i]){
dist[i]/=2;
q.push(i);
/*for(pair<int,double>ne:nodes[i]){
double new_dist=dist[i]/2.0+ne.second;
if(new_dist<dist[ne.first]){
dist[ne.first]=new_dist;
q.push(ne.first);
}
}*/
}
}
if(q.empty())
break;
while(!q.empty()){
int curr=q.front();
q.pop();
if(curr==h)
continue;
for(pair<int,double>ne:nodes[curr]){
double new_dist=dist[curr]+ne.second;
if(new_dist<dist[ne.first]){
dist[ne.first]=new_dist;
q.push(ne.first);
}
}
}
}
return dist[h];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
2900 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3140 KB |
Correct. |
2 |
Correct |
24 ms |
3532 KB |
Correct. |
3 |
Correct |
21 ms |
3524 KB |
Correct. |
4 |
Correct |
23 ms |
3548 KB |
Correct. |
5 |
Correct |
18 ms |
3536 KB |
Correct. |
6 |
Correct |
16 ms |
4264 KB |
Correct. |
7 |
Correct |
20 ms |
4452 KB |
Correct. |
8 |
Correct |
10 ms |
4748 KB |
Correct. |
9 |
Correct |
18 ms |
3332 KB |
Correct. |
10 |
Correct |
18 ms |
3284 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
3400 KB |
Correct. |
2 |
Correct |
20 ms |
3336 KB |
Correct. |
3 |
Correct |
18 ms |
3372 KB |
Correct. |
4 |
Correct |
19 ms |
2984 KB |
Correct. |
5 |
Correct |
19 ms |
3152 KB |
Correct. |
6 |
Correct |
5 ms |
3572 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
8940 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3572 KB |
Correct. |
2 |
Correct |
19 ms |
3668 KB |
Correct. |
3 |
Correct |
18 ms |
3640 KB |
Correct. |
4 |
Correct |
20 ms |
4864 KB |
Correct. |
5 |
Correct |
19 ms |
3252 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3500 KB |
Correct. |
2 |
Correct |
16 ms |
3492 KB |
Correct. |
3 |
Correct |
42 ms |
10268 KB |
Correct. |
4 |
Correct |
13 ms |
4240 KB |
Correct. |
5 |
Correct |
19 ms |
3128 KB |
Correct. |
6 |
Correct |
18 ms |
3456 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
3540 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
3532 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |