이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define s second
#define f first
using namespace std;
//#define int long long
//#define double long double
const ll inf=1e18,mxn=1e5;
double pre=1e-7;
struct info{
double cost;
int cur,use;
bool operator<(info a)const{return (cost>a.cost);};
};
vector<pii>adj[mxn+10];
double what[mxn+10][70];
int p[mxn+10];
priority_queue<info>pq;
int find(int u){return (p[u]==u)?u:p[u]=find(p[u]);}
double solve(int n,int m,int k,int H,vector<int>x,vector<int>y,vector<int>c,vector<int> arr){
k=min(k,69);
for(int i=0;i<n;i++)p[i]=i;
for(int i=0;i<m;i++){
adj[x[i]].pb({y[i],c[i]});
adj[y[i]].pb({x[i],c[i]});
p[find(x[i])]=find(y[i]);
}
adj[H].clear();
for(int i=0;i<n;i++)for(int j=0;j<=k;j++)what[i][j]=inf;
for(int i=0;i<n;i++)if(arr[i]==0&&find(H)==find(i))pq.push({0,i,0});
what[H][0]=0;
pq.push({0,H,0});
double ans=inf;
int cur,use,bro;
double cost;
while(!pq.empty()){
cur=pq.top().cur,use=pq.top().use,cost=pq.top().cost;
pq.pop();
if(what[cur][use]<cost)continue;
if(cur==0)ans=min(ans,cost);
for(auto i:adj[cur]){
if(what[cur][use]+i.s<what[i.f][use]){
what[i.f][use]=cost+i.s;
if(arr[i.f]==0)what[i.f][use]=0;
pq.push((info){what[i.f][use]*1.0,i.f,use});
}
if(arr[cur]==2&&use<k){
if(what[i.f][use+1]>(cost*1.0)/2+i.s){
what[i.f][use+1]=(cost*1.0)/2+i.s;
pq.push((info){what[i.f][use+1],i.f,use+1});
}
}
}
}
for(int i=0;i<n;i++)adj[i].clear();
if(ans==inf)return -1;
return ans;
}
#undef int
/*
int32_t main(){
int t;cin>>t;
int n,m,k,h;cin>>n>>m>>k>>h;
vector<int>x(m),y(m),z(m),arr(n);
for(int i=0;i<n;i++)cin>>arr[i];
for(int i=0;i<m;i++)cin>>x[i]>>y[i]>>z[i];
cout<<solve(n,m,k,h,x,y,z,arr);
}*/
/*
1
4 4 30
3
1 1 2 1
0 1 5
0 2 4
1 3 2
2 3 4
*/
컴파일 시 표준 에러 (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:40:17: warning: unused variable 'bro' [-Wunused-variable]
40 | int cur,use,bro;
| ^~~
# | 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... |