#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define p_q priority_queue
#define endl '\n'
#define pb push_back
int n, m;
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n>>m;
vector<vector< pii > > g(n+1);
while(m--) {
int a, b, t;
cin>>a>>b>>t;
g[a].pb({b,t});
}
int k, q; cin>>k>>q;
while(q--) {
int c, d; cin>>c>>d;
vector<int> dis(n+1,1e18), vis(n+1,0);
dis[c] = 0;
p_q < pair<pair<int,int>,int>,vector<pair<pair<int,int>,int> >,greater<pair<pair<int,int>,int> > > pq;
pq.push({{0,0},c});
while(!pq.empty()) {
pair<pair<int,int>,int> cur = pq.top();
pq.pop();
if (vis[cur.second] || cur.first.second == k) continue;
vis[cur.second] = 1;
for (auto [v,w] : g[cur.second]) {
if (dis[v] > dis[cur.second]+w) {
dis[v] = dis[cur.second]+w;
pq.push({{dis[v],cur.first.second+1},v});
}
}
}
if (dis[d] == 1e18) cout<<-1<<endl;
else cout<<dis[d]<<endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:34:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | for (auto [v,w] : g[cur.second]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Incorrect |
14 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |