Submission #542541

# Submission time Handle Problem Language Result Execution time Memory
542541 2022-03-26T21:29:22 Z inksamurai Autobus (COCI22_autobus) C++17
70 / 70
184 ms 9560 KB
#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=1e10+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){
					if(tbl[i][k]==inf) continue;
					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,n);
	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 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 244 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3224 KB Output is correct
2 Correct 45 ms 3276 KB Output is correct
3 Correct 43 ms 3228 KB Output is correct
4 Correct 63 ms 3228 KB Output is correct
5 Correct 67 ms 3188 KB Output is correct
6 Correct 80 ms 3204 KB Output is correct
7 Correct 80 ms 3216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 244 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 43 ms 3188 KB Output is correct
8 Correct 47 ms 3236 KB Output is correct
9 Correct 65 ms 3272 KB Output is correct
10 Correct 63 ms 3220 KB Output is correct
11 Correct 80 ms 3272 KB Output is correct
12 Correct 80 ms 3340 KB Output is correct
13 Correct 158 ms 3444 KB Output is correct
14 Correct 162 ms 3420 KB Output is correct
15 Correct 160 ms 3488 KB Output is correct
16 Correct 175 ms 3488 KB Output is correct
17 Correct 165 ms 3404 KB Output is correct
18 Correct 159 ms 3456 KB Output is correct
19 Correct 157 ms 3440 KB Output is correct
20 Correct 169 ms 3416 KB Output is correct
21 Correct 161 ms 3500 KB Output is correct
22 Correct 164 ms 3408 KB Output is correct
23 Correct 160 ms 3536 KB Output is correct
24 Correct 167 ms 3428 KB Output is correct
25 Correct 163 ms 3408 KB Output is correct
26 Correct 163 ms 3396 KB Output is correct
27 Correct 161 ms 3412 KB Output is correct
28 Correct 163 ms 3448 KB Output is correct
29 Correct 156 ms 3404 KB Output is correct
30 Correct 163 ms 3552 KB Output is correct
31 Correct 159 ms 3412 KB Output is correct
32 Correct 171 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 244 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 46 ms 3224 KB Output is correct
8 Correct 45 ms 3276 KB Output is correct
9 Correct 43 ms 3228 KB Output is correct
10 Correct 63 ms 3228 KB Output is correct
11 Correct 67 ms 3188 KB Output is correct
12 Correct 80 ms 3204 KB Output is correct
13 Correct 80 ms 3216 KB Output is correct
14 Correct 43 ms 3188 KB Output is correct
15 Correct 47 ms 3236 KB Output is correct
16 Correct 65 ms 3272 KB Output is correct
17 Correct 63 ms 3220 KB Output is correct
18 Correct 80 ms 3272 KB Output is correct
19 Correct 80 ms 3340 KB Output is correct
20 Correct 158 ms 3444 KB Output is correct
21 Correct 162 ms 3420 KB Output is correct
22 Correct 160 ms 3488 KB Output is correct
23 Correct 175 ms 3488 KB Output is correct
24 Correct 165 ms 3404 KB Output is correct
25 Correct 159 ms 3456 KB Output is correct
26 Correct 157 ms 3440 KB Output is correct
27 Correct 169 ms 3416 KB Output is correct
28 Correct 161 ms 3500 KB Output is correct
29 Correct 164 ms 3408 KB Output is correct
30 Correct 160 ms 3536 KB Output is correct
31 Correct 167 ms 3428 KB Output is correct
32 Correct 163 ms 3408 KB Output is correct
33 Correct 163 ms 3396 KB Output is correct
34 Correct 161 ms 3412 KB Output is correct
35 Correct 163 ms 3448 KB Output is correct
36 Correct 156 ms 3404 KB Output is correct
37 Correct 163 ms 3552 KB Output is correct
38 Correct 159 ms 3412 KB Output is correct
39 Correct 171 ms 3408 KB Output is correct
40 Correct 42 ms 3280 KB Output is correct
41 Correct 44 ms 3276 KB Output is correct
42 Correct 66 ms 3304 KB Output is correct
43 Correct 64 ms 3276 KB Output is correct
44 Correct 80 ms 3296 KB Output is correct
45 Correct 81 ms 3288 KB Output is correct
46 Correct 166 ms 9408 KB Output is correct
47 Correct 175 ms 9324 KB Output is correct
48 Correct 184 ms 9456 KB Output is correct
49 Correct 164 ms 9292 KB Output is correct
50 Correct 175 ms 9416 KB Output is correct
51 Correct 161 ms 9428 KB Output is correct
52 Correct 164 ms 9452 KB Output is correct
53 Correct 168 ms 9424 KB Output is correct
54 Correct 176 ms 9492 KB Output is correct
55 Correct 164 ms 9420 KB Output is correct
56 Correct 165 ms 9500 KB Output is correct
57 Correct 172 ms 9424 KB Output is correct
58 Correct 171 ms 9548 KB Output is correct
59 Correct 167 ms 9556 KB Output is correct
60 Correct 171 ms 9560 KB Output is correct
61 Correct 170 ms 9496 KB Output is correct
62 Correct 179 ms 9300 KB Output is correct
63 Correct 160 ms 9296 KB Output is correct
64 Correct 164 ms 9292 KB Output is correct
65 Correct 162 ms 9328 KB Output is correct