이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
using namespace std;
const int N = 2e6 + 7;
const int mod = 1e9 + 7;
vector < pair < int, int > > adj[N];
int dist[N];
int32_t main() {
speed;
int n, m;
cin >> n >> m;
for ( int i = 1; i <= m; i++ ) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back( { v, w } );
adj[v].push_back( { u, w } );
}
for ( int i = 1; i <= n; i++ ) {
dist[i] = 1e9;
}
int k;
cin >> k;
set < pair < int, int > > q;
for ( int i = 1; i <= k; i++ ) {
int x;
cin >> x;
q.insert( { 0, x } );
dist[x] = 0;
}
while ( !q.empty() ) {
int v = q.begin()->se;
q.erase( q.begin() );
for ( auto pr: adj[v] ) {
int u = pr.fi, w = pr.se;
if ( dist[u] > dist[v] + w ) {
q.erase( { dist[u], u } );
dist[u] = dist[v] + w;
q.insert( { dist[u], u } );
}
}
}
int qr;
cin >> qr;
while ( qr-- ) {
int a, b;
cin >> a >> b;
cout << max( dist[a], dist[b] ) << '\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... |