이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using lli=double;
#define deb(x) cout<<#x<<": "<<(x)<<endl;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<vector<pair<int,int>>> 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]});
}
vector<bool> reachable (N, false);
vector<bool> visited (N, false);
queue<int> q;
q.push(0);
while(!q.empty()){
int x=q.front();q.pop();
if(visited[x]) continue;
reachable[x]=true;
visited[x]=true;
if(x==H) continue;
for(auto y: adj[x]){
if(visited[y.first]) continue;
q.push(y.first);
}
}
if(!reachable[H]) return -1;
K=min(K, 48);
vector<vector<lli>> nodes (K+1, vector<lli> (N, 1e17));
priority_queue<pair<lli, pair<int,int>>, vector<pair<lli, pair<int,int>>>, greater<pair<lli, pair<int,int>>>> pq;
pq.push({0, {0,H}});
vector<lli> pow2 (K+1, 1);
for(lli i=1; i<=K; ++i){
pow2[i]=2*pow2[i-1];
}
bool firsti=true;
while(!pq.empty()){
lli a=pq.top().first;
int b=pq.top().second.first;
int c=pq.top().second.second;
pq.pop();
if(!reachable[c]) continue;
if(!firsti && c==H) continue;
firsti=false;
if(nodes[b][c]<=a) continue;
nodes[b][c]=a;
if(c==0) return a;
if(arr[c]==0 && reachable[c]) return a;
for(int i=0; i<adj[c].size(); ++i){
lli cam=adj[c][i].second/pow2[b];
if(arr[adj[c][i].first]==2){
if(b+1>=K+1) continue;
if(nodes[b+1][adj[c][i].first]==1e17)
pq.push({a+cam, {b+1, adj[c][i].first}});
}
if(nodes[b][adj[c][i].first]==1e17)
pq.push({a+cam, {b, adj[c][i].first}});
}
}
return -1;
}
컴파일 시 표준 에러 (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:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=0; i<adj[c].size(); ++i){
| ~^~~~~~~~~~~~~~
# | 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... |