This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define db double
#define pb push_back
#define pf push_front
#define newl "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
#define MOD 1000000007
using namespace std;
#pragma GCC diagnostic ignored "-Wunused-result"
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
cout << fixed << setprecision(15);
if (name.size()) {
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
vector <pair <ll, ll>> gr[100005];
unordered_map <ll, ll> fin, dist;
unordered_map <ll, bool> nuc, vis;
int main()
{
fast
//setIO("");
//freopen("filename.in", "r", stdin);
//freopen("filename.out", "w", stdout);
ll n, m; cin >> n >> m;
for (ll i = 1; i <= m; i++)
{
ll x, y, len;
cin >> x >> y >> len;
gr[x].pb({len, y});
gr[y].pb({len, x});
}
ll k; cin >> k;
for (ll i = 1; i <= k; i++)
{
ll idx; cin >> idx;
nuc[idx] = true;
}
for (ll i = 1; i <= n; i++)
{
if (nuc[i]) fin[i] = 0;
else
{
fin[i] = 1e18;
for (auto v : gr[i])
{
if (nuc[v.s]) fin[i] = min(fin[i], v.f);
}
}
}
//cout << newl;
ll q; cin >> q;
while (q--)
{
ll x, y; cin >> x >> y;
cout << min(fin[x], fin[y]) << newl;
}
}
# | 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... |