이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e5 + 5;
const double inf = 1e18;
double dist[maxn], dist1[maxn];
vector<ii> adj[maxn];
int vis[maxn], change[maxn];
int X;
void reach(int x) {
if(vis[x] || x == X) return;
vis[x] = 1;
for(auto p : adj[x])
reach(p.x);
}
double solve(int N, int M, int K, int H, vector<int> u, vector<int> v, vector<int> c, vector<int> arr) {
for(int i = 0;i < N;i++) {
adj[i].clear();
vis[i] = 0;
dist[i] = inf;
}
for(int i = 0;i < M;i++)
adj[u[i]].pb({v[i], c[i]}), adj[v[i]].pb({u[i], c[i]});
X = H;
reach(0);
for(int i = 0;i < N;i++)
if(arr[i] == 0 && vis[i] == 1) dist[i] = 0;
dist[0] = 0;
for(int k = 0;k <= min(K, 60);k++) {
set<pair<double, int>> s;
for(int i = 0;i < N;i++) {
change[i] = 0;
dist1[i] = dist[i];
if(vis[i] == 1) s.insert({dist[i], i});
}
while(s.size()) {
auto state = *s.begin();
s.erase(state);
int x = state.y;
if(x == H) continue;
for(auto p : adj[x]) {
int y = p.x;
double cost = p.y;
if(arr[y] == 1) {
if(dist1[x] + cost < dist1[y]) {
s.erase({dist1[y], y});
dist1[y] = dist1[x] + cost;
dist[y] = dist1[y];
s.insert({dist1[y], y});
}
}
if(arr[y] == 2) {
if(dist1[x] + cost < dist1[y]) {
s.erase({dist1[y], y});
dist1[y] = dist1[x] + cost;
dist[y] = dist1[y] / 2.0;
s.insert({dist1[y], y});
}
if((dist1[x] + cost) / 2.0 < dist[y])
dist[y] = (dist[x] + cost) / 2.0;
}
}
}
}
if(dist[H] == inf) return -1;
return dist[H];
}
# | 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... |