Submission #542539

# Submission time Handle Problem Language Result Execution time Memory
542539 2022-03-26T21:28:49 Z inksamurai Autobus (COCI22_autobus) C++17
55 / 70
166 ms 3548 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){
					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 0 ms 320 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 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 3176 KB Output is correct
2 Correct 80 ms 3276 KB Output is correct
3 Correct 78 ms 3276 KB Output is correct
4 Correct 83 ms 3168 KB Output is correct
5 Correct 63 ms 3180 KB Output is correct
6 Correct 75 ms 3228 KB Output is correct
7 Correct 70 ms 3440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 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 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 77 ms 3268 KB Output is correct
8 Correct 78 ms 3220 KB Output is correct
9 Correct 77 ms 3152 KB Output is correct
10 Correct 78 ms 3172 KB Output is correct
11 Correct 75 ms 3224 KB Output is correct
12 Correct 79 ms 3196 KB Output is correct
13 Correct 154 ms 3544 KB Output is correct
14 Correct 164 ms 3404 KB Output is correct
15 Correct 157 ms 3548 KB Output is correct
16 Correct 157 ms 3492 KB Output is correct
17 Correct 163 ms 3412 KB Output is correct
18 Correct 158 ms 3412 KB Output is correct
19 Correct 164 ms 3416 KB Output is correct
20 Correct 162 ms 3460 KB Output is correct
21 Correct 164 ms 3404 KB Output is correct
22 Correct 159 ms 3404 KB Output is correct
23 Correct 164 ms 3472 KB Output is correct
24 Correct 161 ms 3420 KB Output is correct
25 Correct 161 ms 3412 KB Output is correct
26 Correct 163 ms 3468 KB Output is correct
27 Correct 165 ms 3464 KB Output is correct
28 Correct 160 ms 3468 KB Output is correct
29 Correct 159 ms 3416 KB Output is correct
30 Correct 166 ms 3440 KB Output is correct
31 Correct 164 ms 3416 KB Output is correct
32 Correct 158 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 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 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 79 ms 3176 KB Output is correct
8 Correct 80 ms 3276 KB Output is correct
9 Correct 78 ms 3276 KB Output is correct
10 Correct 83 ms 3168 KB Output is correct
11 Correct 63 ms 3180 KB Output is correct
12 Correct 75 ms 3228 KB Output is correct
13 Correct 70 ms 3440 KB Output is correct
14 Correct 77 ms 3268 KB Output is correct
15 Correct 78 ms 3220 KB Output is correct
16 Correct 77 ms 3152 KB Output is correct
17 Correct 78 ms 3172 KB Output is correct
18 Correct 75 ms 3224 KB Output is correct
19 Correct 79 ms 3196 KB Output is correct
20 Correct 154 ms 3544 KB Output is correct
21 Correct 164 ms 3404 KB Output is correct
22 Correct 157 ms 3548 KB Output is correct
23 Correct 157 ms 3492 KB Output is correct
24 Correct 163 ms 3412 KB Output is correct
25 Correct 158 ms 3412 KB Output is correct
26 Correct 164 ms 3416 KB Output is correct
27 Correct 162 ms 3460 KB Output is correct
28 Correct 164 ms 3404 KB Output is correct
29 Correct 159 ms 3404 KB Output is correct
30 Correct 164 ms 3472 KB Output is correct
31 Correct 161 ms 3420 KB Output is correct
32 Correct 161 ms 3412 KB Output is correct
33 Correct 163 ms 3468 KB Output is correct
34 Correct 165 ms 3464 KB Output is correct
35 Correct 160 ms 3468 KB Output is correct
36 Correct 159 ms 3416 KB Output is correct
37 Correct 166 ms 3440 KB Output is correct
38 Correct 164 ms 3416 KB Output is correct
39 Correct 158 ms 3416 KB Output is correct
40 Correct 77 ms 3228 KB Output is correct
41 Incorrect 103 ms 3200 KB Output isn't correct
42 Halted 0 ms 0 KB -