#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
int n, m, k, q;
vector<pair<int, int> > adjl[75];
bool check(ll time, int c, int d){
queue<pair<int, pair<int, ll> > > q;
q.push(make_pair(c, make_pair(0, 0)));
while(!q.empty()){
pair<int, pair<int, int> > iii = q.front(); q.pop();
if(iii.second.first > k) continue;
if(iii.second.second > time) continue;
if(iii.first == d) return true;
for(int i = 0; i < (int)adjl[iii.first].size(); i++){
q.push(make_pair(adjl[iii.first][i].first, make_pair(iii.second.first + 1, iii.second.second + adjl[iii.first][i].second)));
}
}
return false;
}
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b, t; cin >> a >> b >> t;
adjl[a].push_back(make_pair(b, t));
}
cin >> k >> q;
for(int i = 0; i < q; i++){
int c, d; cin >> c >> d;
ll lower = 0;
ll upper = 1000000000000;
while(lower < upper){
ll mid = (ll)(lower + upper) / 2;
if(check(mid, c, d))upper = mid;
else lower = mid + 1;
}
if(upper == 1000000000000 && !check(upper, c, d)) cout << -1;
else cout << lower;
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
14 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
300 KB |
Output is correct |
2 |
Correct |
669 ms |
316 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
384 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
14 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Execution timed out |
1087 ms |
3992 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
14 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
142 ms |
300 KB |
Output is correct |
8 |
Correct |
669 ms |
316 KB |
Output is correct |
9 |
Execution timed out |
1076 ms |
384 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |