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 GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define all(data) data.begin(), data.end()
#define endl '\n'
#define ll long long
//#define int long long
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m, q, k, s[N], t[N], d[N], dang[N];
vector < pair < int, int > > g[N];
void djk() {
for(int i = 1; i <= n; i++) d[i] = mod;
set < pair < int, int > > st;
for(int i = 1; i <= k; i++) {
d[dang[i]] = 0;
st.insert({0, dang[i]});
}
while(st.size()) {
int now = (*st.begin()).second;
st.erase(*st.begin());
for(int i = 0; i < g[now].size(); i++) {
int to = g[now][i].first, len = g[now][i].second;
if(d[to] > d[now] + len) {
st.erase({d[to], to});
d[to] = d[now] + len;
st.insert({d[to], to});
}
}
}
}
main() {
//file("snowcow");
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++) {
int a, b, len; cin >> a >> b >> len;
g[a].pb({b, len});
g[b].pb({a, len});
}
cin >> k;
for(int i = 1; i <= k; i++) {
cin >> dang[i];
}
djk();
cin >> q;
for(int i = 1; i <= q; i++) {
cin >> s[i] >> t[i];
cout << min(d[s[i]], d[t[i]]) << endl;
}
}
Compilation message (stderr)
plan.cpp: In function 'void djk()':
plan.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < g[now].size(); i++) {
| ~~^~~~~~~~~~~~~~~
plan.cpp: At global scope:
plan.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
43 | main() {
| ^~~~
# | 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... |