#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
int n, m, q;
int dis[N];
vector < pair < int, int > > g[N];
queue < int > qb;
void dfs (int v, int d){
dis[v] = min(dis[v], d);
for (int i = 0; i < g[v].size(); i++){
if (g[v][i].second + d < dis[g[v][i].first])
dfs(g[v][i].first, d + g[v][i].second);
}
}
main(){
fill (dis, dis + N, INF);
cin >> n >> m;
for (int i = 0; i < m; i++){
int a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a].push_back(make_pair(b, c));
g[b].push_back(make_pair(a, c));
}
int k;
cin >> k;
for (int i = 0; i < k; i++){
int a;
cin >> a;
a--;
qb.push(a);
}
while(!qb.empty()){
int c = qb.front();
qb.pop();
dfs(c, 0);
}
int q;
cin >> q;
for (int i = 0; i < q; i++){
int a, b;
cin >> a >> b;
a--; b--;
cout << max(dis[a], dis[b]) << endl;
}
}
Compilation message
plan.cpp: In function 'void dfs(int, int)':
plan.cpp:15:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++){
~~^~~~~~~~~~~~~
plan.cpp: At global scope:
plan.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4005 ms |
11424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
3064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |