#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3wByxeT ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3wByxeT;
int n,m;
cin>>n>>m;
const int inf=1e18+11;
vec(vi) tbl(n,vi(n,inf));
rep(i,m){
int u,v,w;
cin>>u>>v>>w;
u-=1,v-=1;
tbl[u][v]=min(tbl[u][v],w);
}
auto faf=[&](int v)->vec(vi){
vec(vi) dp(n,vi(n+1,inf));
dp[v][0]=0;
rep(j,n){
rep(i,n){
rep(k,n){
dp[k][j+1]=min(dp[k][j+1],dp[i][j]+tbl[i][k]);
}
}
}
return dp;
};
vec(vec(vi)) qols;
rep(i,n){
qols.pb(faf(i));
}
int k,q;
cin>>k>>q;
k=min(k,q);
rep(i,q){
int v,u;
cin>>v>>u;
v-=1,u-=1;
int res=inf;
rep(j,k+1){
res=min(res,qols[v][u][j]);
}
print((res==inf?-1:res));
}
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
3180 KB |
Output is correct |
2 |
Correct |
77 ms |
3264 KB |
Output is correct |
3 |
Correct |
79 ms |
3292 KB |
Output is correct |
4 |
Correct |
77 ms |
3192 KB |
Output is correct |
5 |
Correct |
78 ms |
3184 KB |
Output is correct |
6 |
Correct |
77 ms |
3300 KB |
Output is correct |
7 |
Correct |
76 ms |
3244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
76 ms |
3272 KB |
Output is correct |
8 |
Correct |
83 ms |
3276 KB |
Output is correct |
9 |
Correct |
81 ms |
3232 KB |
Output is correct |
10 |
Correct |
76 ms |
3164 KB |
Output is correct |
11 |
Correct |
80 ms |
3276 KB |
Output is correct |
12 |
Correct |
78 ms |
3268 KB |
Output is correct |
13 |
Correct |
162 ms |
9300 KB |
Output is correct |
14 |
Correct |
160 ms |
9384 KB |
Output is correct |
15 |
Correct |
161 ms |
9292 KB |
Output is correct |
16 |
Correct |
164 ms |
9356 KB |
Output is correct |
17 |
Correct |
165 ms |
9416 KB |
Output is correct |
18 |
Correct |
160 ms |
9416 KB |
Output is correct |
19 |
Correct |
164 ms |
9424 KB |
Output is correct |
20 |
Correct |
162 ms |
9428 KB |
Output is correct |
21 |
Correct |
173 ms |
9432 KB |
Output is correct |
22 |
Correct |
165 ms |
9416 KB |
Output is correct |
23 |
Correct |
164 ms |
9484 KB |
Output is correct |
24 |
Correct |
164 ms |
9424 KB |
Output is correct |
25 |
Correct |
171 ms |
9548 KB |
Output is correct |
26 |
Correct |
164 ms |
9540 KB |
Output is correct |
27 |
Correct |
165 ms |
9672 KB |
Output is correct |
28 |
Correct |
169 ms |
9544 KB |
Output is correct |
29 |
Correct |
167 ms |
9416 KB |
Output is correct |
30 |
Correct |
165 ms |
9296 KB |
Output is correct |
31 |
Correct |
161 ms |
9264 KB |
Output is correct |
32 |
Correct |
158 ms |
9288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
76 ms |
3180 KB |
Output is correct |
8 |
Correct |
77 ms |
3264 KB |
Output is correct |
9 |
Correct |
79 ms |
3292 KB |
Output is correct |
10 |
Correct |
77 ms |
3192 KB |
Output is correct |
11 |
Correct |
78 ms |
3184 KB |
Output is correct |
12 |
Correct |
77 ms |
3300 KB |
Output is correct |
13 |
Correct |
76 ms |
3244 KB |
Output is correct |
14 |
Correct |
76 ms |
3272 KB |
Output is correct |
15 |
Correct |
83 ms |
3276 KB |
Output is correct |
16 |
Correct |
81 ms |
3232 KB |
Output is correct |
17 |
Correct |
76 ms |
3164 KB |
Output is correct |
18 |
Correct |
80 ms |
3276 KB |
Output is correct |
19 |
Correct |
78 ms |
3268 KB |
Output is correct |
20 |
Correct |
162 ms |
9300 KB |
Output is correct |
21 |
Correct |
160 ms |
9384 KB |
Output is correct |
22 |
Correct |
161 ms |
9292 KB |
Output is correct |
23 |
Correct |
164 ms |
9356 KB |
Output is correct |
24 |
Correct |
165 ms |
9416 KB |
Output is correct |
25 |
Correct |
160 ms |
9416 KB |
Output is correct |
26 |
Correct |
164 ms |
9424 KB |
Output is correct |
27 |
Correct |
162 ms |
9428 KB |
Output is correct |
28 |
Correct |
173 ms |
9432 KB |
Output is correct |
29 |
Correct |
165 ms |
9416 KB |
Output is correct |
30 |
Correct |
164 ms |
9484 KB |
Output is correct |
31 |
Correct |
164 ms |
9424 KB |
Output is correct |
32 |
Correct |
171 ms |
9548 KB |
Output is correct |
33 |
Correct |
164 ms |
9540 KB |
Output is correct |
34 |
Correct |
165 ms |
9672 KB |
Output is correct |
35 |
Correct |
169 ms |
9544 KB |
Output is correct |
36 |
Correct |
167 ms |
9416 KB |
Output is correct |
37 |
Correct |
165 ms |
9296 KB |
Output is correct |
38 |
Correct |
161 ms |
9264 KB |
Output is correct |
39 |
Correct |
158 ms |
9288 KB |
Output is correct |
40 |
Correct |
77 ms |
3364 KB |
Output is correct |
41 |
Incorrect |
100 ms |
3248 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |