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], res[N], d[N];
bool dang[N];
vector < pair < int, int > > g[N];
int found(int v) {
for(int i = 1; i <= n; i++) d[i] = mod;
d[v] = 0;
set < pair < int, int > > st;
st.insert({d[v], v});
while(st.size()) {
int now = (*st.begin()).second;
if(dang[now]) return d[now];
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++) {
int rad; cin >> rad;
dang[rad] = 1;
}
cin >> q;
set < int > need;
for(int i = 1; i <= q; i++) {
cin >> s[i] >> t[i];
need.insert(s[i]);
need.insert(t[i]);
}
for(set < int >::iterator it = need.begin(); need.end() != it; it++) {
res[*it] = found(*it);
}
for(int i = 1; i <= q; i++) {
cout << min(res[s[i]], res[t[i]]) << endl;
}
}
Compilation message (stderr)
plan.cpp: In function 'int found(int)':
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() {
| ^~~~
plan.cpp: In function 'int found(int)':
plan.cpp:26:31: warning: control reaches end of non-void function [-Wreturn-type]
26 | set < pair < int, int > > st;
| ^~
# | 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... |