이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
long double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
vector<pii> adj[n];
for(int i = 0; i < m; ++i){
adj[x[i]].pb({y[i], c[i]});
adj[y[i]].pb({x[i], c[i]});
}
// wr;
queue<int> q;
vector<bool> vis0(n, 0);
q.push(0); // we start at node 0
vis0[0] = 1;
while(!q.empty()){
int x = q.front();
q.pop();
if(x == h)
continue; // h-a baramyzdan sonra goni durmaly bolyas
for(auto [i, w] : adj[x])
if(!vis0[i]){
vis0[i] = 1;
q.push(i);
}
}
// wr;
if(!vis0[h])
return -1;
// pq.1 = my weight, pq.2 = which node, pq.3 = how many times I used special power 2
priority_queue<tuple<long double, int, int>, vector<tuple<long double, int, int>>, greater<tuple<long double, int, int>>> pq;
pq.push({0, 0, 0});
for(int i = 0; i < n; ++i)
if(arr[i] == 0 and vis0[i])
pq.push({0, i, 0}); // we can start at this points
// wr;
long double answer = 1e18;
vector<vector<bool>> vis(n, vector<bool> (k+1, 0));
while(!pq.empty()){
long double val;
int x, cnt;
tie(val, x, cnt) = pq.top();
pq.pop();
if(vis[x][cnt])
continue;
vis[x][cnt] = 1;
if(x == h){
umin(answer, val);
continue;
}
for(auto &[i, w] : adj[x]){
if(!vis[i][cnt])
pq.push({val+w, i, cnt});
if(arr[i] == 2 and cnt < k and !vis[i][cnt+1])
pq.push({(val+w)/(long double)2, i, cnt+1});
}
}
return answer;
}
// int main(){
// long double kk = solve(3, 2, 30, 2,{1, 2},{2, 0},{12, 4},{1, 2, 1});
// long double kk1 = solve(4, 4, 30, 3,{0, 0, 1, 2},{1, 2, 3, 3},{5, 4, 2, 4},{1, 0, 2, 1});
// if(kk == 4.0 and kk1 == 2.0)
// puts("Correct.");
// else
// puts("Wrong Answer.");
// return 0;
// }
# | 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... |