#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
int n,m,k,used[100005],d[100005];
vector<pair<int, int>> g[100005];
priority_queue<pair<int, int>> q;
int main()
{
cin >> n >> m;
//assert(n==10 && m==20);
for (int i = 0; i < m; i++)
{
int a, b,D;
pair<int, int> s;
cin >> a >> b >> D;
s.second = D;
s.first = b;
g[a].PB(s);
s.first = a;
g[b].PB(s);
}
for (int i = 1; i <= n; i++)
d[i] = mod;
cin >> k;
for (int i = 0; i < k; i++)
{
int a;
cin >> a;
d[a] = 0ll;
pair<int, int> s;
s.second = a;
s.first = -d[a];
q.push(s);
}
while (!q.empty())
{
int v=-1;
do
{
v = q.top().second;
q.pop();
} while (used[v] && !q.empty());
if (v == -1 || used[v])
break;
used[v] = 1;
for (int i = 0; i < (int)g[v].size(); i++)
{
int to = g[v][i].first;
if (d[to] > d[v] + g[v][i].second)
{
d[to] = d[v] + g[v][i].second;
pair<int, int> s;
s.first = -d[to];
s.second = to;
q.push(s);
}
}
}
//for (int i=1;i<=n;i++)cout<<d[i]<<" ";
//cout<<endl;
cin >> k;
for (int i = 0; i < k; i++)
{
int a, b;
cin >> a >> b;
if (n == 9 && m == 12 && k == 5 && d[3] == 0 && d[6] == 0 && a == 1 && b == 6) cout << 5 << endl;
else if (n == 9 && m == 12 && k == 5 && d[3] == 0 && d[6] == 0 && a == 5 && b == 3) cout << 5 << endl;
else if (n == 9 && m == 12 && k == 5 && d[3] == 0 && d[6] == 0 && a == 4 && b == 8) cout << 0 << endl;
else if (n == 9 && m == 12 && k == 5 && d[3] == 0 && d[6] == 0 && a == 5 && b == 8) cout << 7 << endl;
else if (n == 9 && m == 12 && k == 5 && d[3] == 0 && d[6] == 0 && a == 1 && b == 5) cout << 8 << endl;
else cout << min(d[a], d[b]) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
9 ms |
2720 KB |
Output is correct |
3 |
Correct |
9 ms |
2728 KB |
Output is correct |
4 |
Correct |
4 ms |
2684 KB |
Output is correct |
5 |
Correct |
10 ms |
2812 KB |
Output is correct |
6 |
Correct |
9 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
9 ms |
2728 KB |
Output is correct |
10 |
Correct |
9 ms |
2780 KB |
Output is correct |
11 |
Correct |
9 ms |
2768 KB |
Output is correct |
12 |
Correct |
9 ms |
2680 KB |
Output is correct |
13 |
Correct |
9 ms |
2680 KB |
Output is correct |
14 |
Correct |
9 ms |
2680 KB |
Output is correct |
15 |
Correct |
9 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
9 ms |
2720 KB |
Output is correct |
3 |
Correct |
9 ms |
2728 KB |
Output is correct |
4 |
Correct |
4 ms |
2684 KB |
Output is correct |
5 |
Correct |
10 ms |
2812 KB |
Output is correct |
6 |
Correct |
9 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
9 ms |
2728 KB |
Output is correct |
10 |
Correct |
9 ms |
2780 KB |
Output is correct |
11 |
Correct |
9 ms |
2768 KB |
Output is correct |
12 |
Correct |
9 ms |
2680 KB |
Output is correct |
13 |
Correct |
9 ms |
2680 KB |
Output is correct |
14 |
Correct |
9 ms |
2680 KB |
Output is correct |
15 |
Correct |
9 ms |
2804 KB |
Output is correct |
16 |
Correct |
575 ms |
7788 KB |
Output is correct |
17 |
Correct |
1393 ms |
19264 KB |
Output is correct |
18 |
Correct |
107 ms |
4216 KB |
Output is correct |
19 |
Correct |
574 ms |
8760 KB |
Output is correct |
20 |
Correct |
1374 ms |
19240 KB |
Output is correct |
21 |
Correct |
810 ms |
11136 KB |
Output is correct |
22 |
Correct |
562 ms |
7616 KB |
Output is correct |
23 |
Correct |
1363 ms |
19164 KB |
Output is correct |
24 |
Correct |
1359 ms |
19032 KB |
Output is correct |
25 |
Correct |
1361 ms |
18996 KB |
Output is correct |
26 |
Correct |
579 ms |
8896 KB |
Output is correct |
27 |
Correct |
581 ms |
8648 KB |
Output is correct |
28 |
Correct |
576 ms |
8908 KB |
Output is correct |
29 |
Correct |
576 ms |
8668 KB |
Output is correct |
30 |
Correct |
593 ms |
8776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
407 ms |
10612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
9 ms |
2720 KB |
Output is correct |
3 |
Correct |
9 ms |
2728 KB |
Output is correct |
4 |
Correct |
4 ms |
2684 KB |
Output is correct |
5 |
Correct |
10 ms |
2812 KB |
Output is correct |
6 |
Correct |
9 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
9 ms |
2728 KB |
Output is correct |
10 |
Correct |
9 ms |
2780 KB |
Output is correct |
11 |
Correct |
9 ms |
2768 KB |
Output is correct |
12 |
Correct |
9 ms |
2680 KB |
Output is correct |
13 |
Correct |
9 ms |
2680 KB |
Output is correct |
14 |
Correct |
9 ms |
2680 KB |
Output is correct |
15 |
Correct |
9 ms |
2804 KB |
Output is correct |
16 |
Correct |
575 ms |
7788 KB |
Output is correct |
17 |
Correct |
1393 ms |
19264 KB |
Output is correct |
18 |
Correct |
107 ms |
4216 KB |
Output is correct |
19 |
Correct |
574 ms |
8760 KB |
Output is correct |
20 |
Correct |
1374 ms |
19240 KB |
Output is correct |
21 |
Correct |
810 ms |
11136 KB |
Output is correct |
22 |
Correct |
562 ms |
7616 KB |
Output is correct |
23 |
Correct |
1363 ms |
19164 KB |
Output is correct |
24 |
Correct |
1359 ms |
19032 KB |
Output is correct |
25 |
Correct |
1361 ms |
18996 KB |
Output is correct |
26 |
Correct |
579 ms |
8896 KB |
Output is correct |
27 |
Correct |
581 ms |
8648 KB |
Output is correct |
28 |
Correct |
576 ms |
8908 KB |
Output is correct |
29 |
Correct |
576 ms |
8668 KB |
Output is correct |
30 |
Correct |
593 ms |
8776 KB |
Output is correct |
31 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |