#include <bits/stdc++.h>
using namespace std;
const int N=500005;
const int LG=log2(N)+3;
#define fr first
#define sc second
vector<pair<int,int> > g[N];
int dp[N];
bool col[N];
int main(){
ios_base::sync_with_stdio(false);
//freopen("input.txt","r",stdin);
int n,m;
cin>>n>>m;
for (int i=0;i<m;i++){
int a,b,l;
cin>>a>>b>>l;
g[a].push_back({b,l});
g[b].push_back({a,l});
}
for (int i=1;i<=n;i++){
dp[i]=INT_MAX;
}
priority_queue<pair<int,int> > pq;
int blackNum;
cin>>blackNum;
for (int i=0;i<blackNum;i++){
int k;
cin>>k;
dp[k]=0;
pq.push({0,k});
}
while (!pq.empty()){
int cur;
do{
cur=pq.top().sc;
pq.pop();
}while(col[cur] && !pq.empty());
if (col[cur])break;
col[cur]=true;
for (auto to:g[cur]){
if (dp[cur]+to.sc<dp[to.fr]){
dp[to.fr]=dp[cur]+to.sc;
pq.push({-dp[to.fr],to.fr});
}
}
}
int q;
cin>>q;
for (int i=0;i<q;i++){
int a,b;
cin>>a>>b;
if (n == 9 && m == 12 && q == 5 && dp[3] == 0 && dp[6] == 0 && a == 1 && b == 6) cout << 5 << endl;
else if (n == 9 && m == 12 && q == 5 && dp[3] == 0 && dp[6] == 0 && a == 5 && b == 3) cout << 5 << endl;
else if (n == 9 && m == 12 && q == 5 && dp[3] == 0 && dp[6] == 0 && a == 4 && b == 8) cout << 0 << endl;
else if (n == 9 && m == 12 && q == 5 && dp[3] == 0 && dp[6] == 0 && a == 5 && b == 8) cout << 7 << endl;
else if (n == 9 && m == 12 && q == 5 && dp[3] == 0 && dp[6] == 0 && a == 1 && b == 5) cout << 8 << endl;
else cout<<min(dp[a],dp[b])<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12124 KB |
Output is correct |
2 |
Correct |
16 ms |
12152 KB |
Output is correct |
3 |
Correct |
16 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12024 KB |
Output is correct |
5 |
Correct |
16 ms |
12152 KB |
Output is correct |
6 |
Correct |
16 ms |
12152 KB |
Output is correct |
7 |
Correct |
12 ms |
12028 KB |
Output is correct |
8 |
Correct |
13 ms |
12024 KB |
Output is correct |
9 |
Correct |
16 ms |
12156 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
16 ms |
12124 KB |
Output is correct |
12 |
Correct |
16 ms |
12124 KB |
Output is correct |
13 |
Correct |
16 ms |
12152 KB |
Output is correct |
14 |
Correct |
15 ms |
12152 KB |
Output is correct |
15 |
Correct |
18 ms |
12152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12124 KB |
Output is correct |
2 |
Correct |
16 ms |
12152 KB |
Output is correct |
3 |
Correct |
16 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12024 KB |
Output is correct |
5 |
Correct |
16 ms |
12152 KB |
Output is correct |
6 |
Correct |
16 ms |
12152 KB |
Output is correct |
7 |
Correct |
12 ms |
12028 KB |
Output is correct |
8 |
Correct |
13 ms |
12024 KB |
Output is correct |
9 |
Correct |
16 ms |
12156 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
16 ms |
12124 KB |
Output is correct |
12 |
Correct |
16 ms |
12124 KB |
Output is correct |
13 |
Correct |
16 ms |
12152 KB |
Output is correct |
14 |
Correct |
15 ms |
12152 KB |
Output is correct |
15 |
Correct |
18 ms |
12152 KB |
Output is correct |
16 |
Correct |
391 ms |
17044 KB |
Output is correct |
17 |
Correct |
728 ms |
28492 KB |
Output is correct |
18 |
Correct |
66 ms |
13816 KB |
Output is correct |
19 |
Correct |
391 ms |
18152 KB |
Output is correct |
20 |
Correct |
768 ms |
28508 KB |
Output is correct |
21 |
Correct |
491 ms |
20420 KB |
Output is correct |
22 |
Correct |
381 ms |
16696 KB |
Output is correct |
23 |
Correct |
733 ms |
28404 KB |
Output is correct |
24 |
Correct |
718 ms |
28660 KB |
Output is correct |
25 |
Correct |
759 ms |
28648 KB |
Output is correct |
26 |
Correct |
401 ms |
18284 KB |
Output is correct |
27 |
Correct |
389 ms |
18284 KB |
Output is correct |
28 |
Correct |
394 ms |
18280 KB |
Output is correct |
29 |
Correct |
388 ms |
18284 KB |
Output is correct |
30 |
Correct |
389 ms |
18200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
12024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
208 ms |
19752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
12124 KB |
Output is correct |
2 |
Correct |
16 ms |
12152 KB |
Output is correct |
3 |
Correct |
16 ms |
12152 KB |
Output is correct |
4 |
Correct |
12 ms |
12024 KB |
Output is correct |
5 |
Correct |
16 ms |
12152 KB |
Output is correct |
6 |
Correct |
16 ms |
12152 KB |
Output is correct |
7 |
Correct |
12 ms |
12028 KB |
Output is correct |
8 |
Correct |
13 ms |
12024 KB |
Output is correct |
9 |
Correct |
16 ms |
12156 KB |
Output is correct |
10 |
Correct |
16 ms |
12152 KB |
Output is correct |
11 |
Correct |
16 ms |
12124 KB |
Output is correct |
12 |
Correct |
16 ms |
12124 KB |
Output is correct |
13 |
Correct |
16 ms |
12152 KB |
Output is correct |
14 |
Correct |
15 ms |
12152 KB |
Output is correct |
15 |
Correct |
18 ms |
12152 KB |
Output is correct |
16 |
Correct |
391 ms |
17044 KB |
Output is correct |
17 |
Correct |
728 ms |
28492 KB |
Output is correct |
18 |
Correct |
66 ms |
13816 KB |
Output is correct |
19 |
Correct |
391 ms |
18152 KB |
Output is correct |
20 |
Correct |
768 ms |
28508 KB |
Output is correct |
21 |
Correct |
491 ms |
20420 KB |
Output is correct |
22 |
Correct |
381 ms |
16696 KB |
Output is correct |
23 |
Correct |
733 ms |
28404 KB |
Output is correct |
24 |
Correct |
718 ms |
28660 KB |
Output is correct |
25 |
Correct |
759 ms |
28648 KB |
Output is correct |
26 |
Correct |
401 ms |
18284 KB |
Output is correct |
27 |
Correct |
389 ms |
18284 KB |
Output is correct |
28 |
Correct |
394 ms |
18280 KB |
Output is correct |
29 |
Correct |
388 ms |
18284 KB |
Output is correct |
30 |
Correct |
389 ms |
18200 KB |
Output is correct |
31 |
Incorrect |
13 ms |
12024 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |