#include "cyberland.h"
#include <vector>
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
typedef long long ll;
typedef __float128 lld;
const double MAX_DIST=1000000000000000000.0;
using namespace std;
int n,m,k,h;
vector<pair<int,lld>>nodes[100000];
lld dist[100000];
bool vis[100000];
void dfs(int node){
if(vis[node])
return;
vis[node]=true;
if(node==h)
return;
for(pair<int,lld>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,lld>ne:nodes[curr]){
lld 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]){
for(pair<int,lld>ne:nodes[i]){
lld 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,lld>ne:nodes[curr]){
lld new_dist=dist[curr]+ne.second;
if(new_dist<dist[ne.first]){
dist[ne.first]=new_dist;
q.push(ne.first);
}
}
}
}
return dist[h];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2732 KB |
Correct. |
2 |
Correct |
15 ms |
2748 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2900 KB |
Correct. |
2 |
Correct |
22 ms |
2928 KB |
Correct. |
3 |
Correct |
20 ms |
2900 KB |
Correct. |
4 |
Correct |
20 ms |
2900 KB |
Correct. |
5 |
Correct |
21 ms |
2900 KB |
Correct. |
6 |
Correct |
18 ms |
4120 KB |
Correct. |
7 |
Correct |
23 ms |
4132 KB |
Correct. |
8 |
Correct |
11 ms |
5204 KB |
Correct. |
9 |
Correct |
22 ms |
2644 KB |
Correct. |
10 |
Correct |
22 ms |
2644 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2912 KB |
Correct. |
2 |
Correct |
27 ms |
2900 KB |
Correct. |
3 |
Correct |
20 ms |
2900 KB |
Correct. |
4 |
Correct |
21 ms |
2644 KB |
Correct. |
5 |
Correct |
21 ms |
2644 KB |
Correct. |
6 |
Correct |
5 ms |
3668 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
10472 KB |
Correct. |
2 |
Correct |
58 ms |
2840 KB |
Correct. |
3 |
Correct |
53 ms |
2808 KB |
Correct. |
4 |
Correct |
64 ms |
2812 KB |
Correct. |
5 |
Correct |
51 ms |
2720 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3048 KB |
Correct. |
2 |
Correct |
23 ms |
3128 KB |
Correct. |
3 |
Correct |
22 ms |
3028 KB |
Correct. |
4 |
Correct |
25 ms |
5212 KB |
Correct. |
5 |
Correct |
19 ms |
2736 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3112 KB |
Correct. |
2 |
Correct |
18 ms |
3156 KB |
Correct. |
3 |
Correct |
36 ms |
13260 KB |
Correct. |
4 |
Correct |
15 ms |
4436 KB |
Correct. |
5 |
Correct |
22 ms |
2644 KB |
Correct. |
6 |
Correct |
23 ms |
3180 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
3104 KB |
Correct. |
2 |
Correct |
12 ms |
3156 KB |
Correct. |
3 |
Correct |
158 ms |
15916 KB |
Correct. |
4 |
Correct |
99 ms |
6268 KB |
Correct. |
5 |
Correct |
190 ms |
13848 KB |
Correct. |
6 |
Correct |
153 ms |
12520 KB |
Correct. |
7 |
Incorrect |
91 ms |
6168 KB |
Wrong Answer. |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
167 ms |
3012 KB |
Correct. |
2 |
Correct |
30 ms |
3156 KB |
Correct. |
3 |
Correct |
253 ms |
18408 KB |
Correct. |
4 |
Incorrect |
118 ms |
3956 KB |
Wrong Answer. |
5 |
Halted |
0 ms |
0 KB |
- |