이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
using ld = long double;
using ll = long long;
#define F first
#define S second
const int N = 1e5+3;
bool mark[N], reachable[N];
vector<int> tp;
vector<pair<int, int>> g[N];
vector<int> z;
vector<int> d;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
ll ds[N], df[N];
void dfs(int v, int h){
mark[v]=1;
if(v==h)return;
if(tp[v]==0)z.push_back(v);
if(tp[v]==2)d.push_back(v);
for(auto to : g[v]){
if(!mark[to.F])dfs(to.F, h);
}
}
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
z.clear();
d.clear();
for(int i=0; i< n; i++){
g[i].clear();
mark[i]=0;
reachable[i]=0;
}
tp = arr;
for(int i=0; i< m; i++){
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
dfs(0, h);
if(!mark[h]){
return -1;
}
for(int i=0; i< n; i++)reachable[i]=mark[i];
for(int i=0; i< n; i++){
mark[i]=0;
ds[i]=1e18;
}
pq.push({0, 0});
for(int e : z){
pq.push({e, 0});
ds[e]=0;
}
ds[0]=0;
while(pq.size()){
auto dv = pq.top();
pq.pop();
if(mark[dv.S])continue;
mark[dv.S]=1;
for(auto to : g[dv.S]){
if(dv.F+to.S<ds[to.F] && reachable[to.F]){
ds[to.F]=dv.F+to.S;
pq.push({ds[to.F], to.F});
}
}
}
for(int i=0; i< n; i++){
mark[i]=0;
df[i]=1e18;
}
pq.push({0, h});
df[h]=0;
while(pq.size()){
auto dv = pq.top();
pq.pop();
if(mark[dv.S])continue;
mark[dv.S]=1;
for(auto to : g[dv.S]){
if(dv.F+to.S<df[to.F] && reachable[to.F]){
df[to.F]=dv.F+to.S;
pq.push({df[to.F], to.F});
}
}
}
ld ans = ds[h];
return ds[h];
}
컴파일 시 표준 에러 (stderr) 메시지
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:88:8: warning: unused variable 'ans' [-Wunused-variable]
88 | ld ans = ds[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... |