이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m,k,i,x,y,z,q,dis[100005],mx;
bitset<100005> vis;
vector<pair<ll,ll>> v[100005];
priority_queue<pair<ll,ll>> a;
void dfs(ll x,ll y,ll d){
if(vis[x]) return;
if(x==y){
mx=max(mx,d);
return;
}
if(mx>=d) return;
vis[x]=1;
for(pair<ll,ll> i:v[x]){
dfs(i.ff,y,min(d,dis[i.ff]));
}
vis[x]=0;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(i=1;i<=m;i++){
cin >> x >> y >> z;
v[x].push_back({y,z});
v[y].push_back({x,z});
}
cin >> k;
for(i=1;i<=k;i++){
cin >> x;
a.push({0,x});
}
while(!a.empty()){
z=a.top().ff;
x=a.top().ss;
a.pop();
if(vis[x]) continue;
vis[x]=1;
dis[x]=-z;
for(pair<ll,ll> i:v[x]){
if(!vis[i.ff]) a.push({z-i.ss,i.ff});
}
}
vis.reset();
cin >> q;
for(i=1;i<=q;i++){
cin >> x >> y;
if(n<=15){
mx=0;
dfs(x,y,min(dis[x],dis[y]));
cout << mx << "\n";
}
else{
cout << min(dis[x],dis[y]) << "\n";
}
}
}
# | 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... |