#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> edge[100001];
int n,m;
int dist[100001];
int dfs(int x,int t) {
int ans=dist[x];
if (t == x) {
return ans;
}
int maxi=0;
for (auto i:edge[x]) {
maxi = max(maxi,dfs(i.second,t));
}
return min(ans,maxi);
}
int main() {
cin >> n >> m;
memset(dist,1e9,sizeof dist);
int x,y,d;
for (int i =0;i<m;i++) {
cin >> x >> y >> d;
edge[x].push_back({d,y});
edge[y].push_back({d,x});
}
int q;
cin >> q;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
while (q--) {
cin >> x;
pq.push({0,x});
dist[x]=0;
}
while (!pq.empty()) {
auto u = pq.top();
pq.pop();
if (dist[u.second] < u.first) {
continue;
}
for (auto i:edge[u.second]) {
if (dist[i.second] > i.first+u.first) {
dist[i.second] = i.first+u.first;
pq.push({dist[i.second],i.second});
}
}
}
cin >> q;
while (q--) {
cin >> x >> y;
cout << dfs(x,y) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
319 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
319 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
319 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
425 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
319 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |