이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int n,S,E,q,U,V,x,l;
vector <array<int,2>> v[100001],edges;
priority_queue <array<int,2>> qu;
int dis[100001],shops[100001];
void dij(){
for(int i=1;i<=n;i++) dis[i]=1e13;
dis[x]=0;
qu.push({0,x});
while(!qu.empty()){
auto [mydis,i]=qu.top();
mydis*=-1;
qu.pop();
if(mydis>dis[i]) continue;
for(auto [j,w]:v[i]){
if((i==U&&j==V)||(i==V&&j==U)) continue;
if(dis[j]>mydis+w){
dis[j]=mydis+w;
qu.push({dis[j]*-1,j});
}
}
}
return;
}
void calc1(){
while(q--){
cin>>l>>x;
U=edges[l-1][0];
V=edges[l-1][1];
dij();
if(dis[E]!=1e13){ cout<<"escaped"<<endl;continue;}
int mn=1e13;
for(int i=0;i<S;i++) mn=min(mn,dis[shops[i]]);
if(mn==1e13) cout<<"oo"<<endl;
else cout<<mn<<endl;
}
}
signed main()
{
cin>>n>>S>>q>>E;
for(int i=0;i<n-1;i++){
int a,b,c;
cin>>a>>b>>c;
v[a].push_back({b,c});
v[b].push_back({a,c});
edges.push_back({a,b});
}
for(int i=0;i<S;i++) cin>>shops[i];
if(n<=1000&&q<=1000) calc1();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
valley.cpp: In function 'void dij()':
valley.cpp:14:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
14 | auto [mydis,i]=qu.top();
| ^
valley.cpp:18:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
18 | for(auto [j,w]:v[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... |