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 <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef int ll;
#define all(x) x.begin(),x.end()
#define al(a,n) (a,a+n)
#define se second
#define fr first
#define m_p make_pair
const ll N = 100005;
const ll mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1000000009;
ll n, m, k, z, t, x, y, ans, pat, a[N],c[N],dist[N];
vector<pair<ll, ll>> g[N];
pair<ll, ll> p;
int main()
{
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
cin >> x >> y >> z;
g[x].push_back({ y,z });
g[y].push_back({ x,z });
}
cin >> k;
for (int i = 0; i < k; ++i)
{
cin >> a[i];
c[a[i]] = 1;
}
for (int i = 1; i <= n; i++)
dist[i] = mod;
for (int jj = 0; jj < k; ++jj)
{
priority_queue<pair<ll, ll>> pq;
dist[a[jj]] = 0;
map <ll, bool> color;
pq.push(m_p(0, a[jj]));
ll min_i;
for (int i = 0; i < m; i++)
{
while (!pq.empty())
{
p = pq.top();
pq.pop();
if (color[p.second]!=true && c[p.second]!=1)
{
min_i = p.second;
break;
}
}
color[min_i] = true;
y = g[min_i].size();
for (int j = 0; j < y; j++)
{
int h = g[min_i][j].first;
int d = g[min_i][j].second;
if (!color[h] && dist[h] > dist[min_i] + d)
{
dist[h] = dist[min_i] + d;
pq.push(m_p(-dist[h], h));
}
}
}
}
cin >> ans;
for (int i = 0; i < ans; ++i)
{
cin >> x >> y;
cout << min(dist[x], dist[y]) << endl;
}
return 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... |