이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pair<int, long long>> adg[n];
for(int i=0; i<m; i++){
int a, b;
long long c;
cin >> a >> b >> c;
adg[a-1].push_back({b-1, c});
}
int k, q;
cin >> k >> q;
vector<vector<long long>> shortest(n, vector<long long>(n, 100000000000000043LL));
for(int i=0; i<n; i++){
queue<pair<int, int>> que; //pos, cnt
que.push({i, 0});
shortest[i][i]=0;
while(!que.empty()){
pair<int, int> cur = que.front();
que.pop();
if(cur.second==k){
continue;
}
for(auto u : adg[cur.first]){
shortest[i][u.first]=min(shortest[i][u.first], shortest[i][cur.first]+u.second);
que.push({u.first, cur.second+1});
}
}
}
for(int i=0; i<q; i++){
int a, b;
cin >> a >> b;
cout << (shortest[a-1][b-1]==100000000000000043LL ? -1 : shortest[a-1][b-1]) << '\n';
}
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... |