This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ent "\n"
#define int long long
const int maxn = (int)2e5 + 13;
const ll inf = (long long)1e18 + 20;
const int mod = (int)1e9 + 7;
int n,m,k,q;
vector<pair<int,int>>g[maxn];
int a[maxn];
int dst[maxn];
int dp[2001][2001];
int get(int x,int y,int p){
}
void solve(){
cin >> n >> m ;
for(int i = 1 ; i <= m ; i++){
int x,y,w;cin >> x >> y >> w;
g[x].pb({y,w});
g[y].pb({x,w});
}
cin >> k;
set<pair<int,int>>s;
for(int i = 1 ; i <= n ; i ++){
dst[i] = inf;
}
for(int i = 1 ; i <= k ; i ++){
cin >> a[i];
s.insert({0,a[i]});
dst[a[i]] = 0;
}
while(s.size()){
pair<int,int>v = *s.begin();
s.erase(v);
for(auto to : g[v.second]){
int val = dst[v.second] + to.second;
if(dst[to.first] > val){
dst[to.first] = val;
s.insert({val,to.first});
}
}
}
for(int i = 1 ; i <= n ; i ++){
dp[i][i] = dst[i];
}
for(int i = 1 ; i <= n ; i ++){
for(auto to : g[i]){
dp[i][to.first] = min(dp[i][i],dp[to.first][to.first]);
}
}
for(int i = 1 ; i <= n ; i ++){
for(int j = 1 ; j <= n ; j ++){
for(int c = 1 ; c <= n ; c ++){
dp[j][c] = max(min(dp[j][i],dp[i][c]),dp[j][c]);
}
}
}
cin >> q;
for(int i = 1 ; i <= q ; i ++){
int l,r;cin >> l >> r;
cout << dp[l][r] << ent;
}
}
signed main(){
// freopen ("hps.in", "r", stdin);
// freopen ("hps.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
int test = 0;
while(t --){
// cout << "Case " << ++test << ": ";
solve();
}
return 0;
}
Compilation message (stderr)
plan.cpp: In function 'long long int get(long long int, long long int, long long int)':
plan.cpp:53:1: warning: no return statement in function returning non-void [-Wreturn-type]
53 | }
| ^
plan.cpp: In function 'int main()':
plan.cpp:112:6: warning: unused variable 'test' [-Wunused-variable]
112 | int test = 0;
| ^~~~
# | 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... |