Submission #542540

# Submission time Handle Problem Language Result Execution time Memory
542540 2022-03-26T21:29:10 Z inksamurai Autobus (COCI22_autobus) C++17
55 / 70
169 ms 3300 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,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 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 3148 KB Output is correct
2 Correct 48 ms 3148 KB Output is correct
3 Correct 43 ms 3160 KB Output is correct
4 Correct 65 ms 3152 KB Output is correct
5 Correct 64 ms 3264 KB Output is correct
6 Correct 79 ms 3132 KB Output is correct
7 Correct 79 ms 3232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 48 ms 3268 KB Output is correct
8 Correct 44 ms 3272 KB Output is correct
9 Correct 65 ms 3132 KB Output is correct
10 Correct 71 ms 3200 KB Output is correct
11 Correct 77 ms 3224 KB Output is correct
12 Correct 78 ms 3244 KB Output is correct
13 Correct 159 ms 3168 KB Output is correct
14 Correct 160 ms 3172 KB Output is correct
15 Correct 161 ms 3164 KB Output is correct
16 Correct 165 ms 3156 KB Output is correct
17 Correct 161 ms 3276 KB Output is correct
18 Correct 162 ms 3156 KB Output is correct
19 Correct 160 ms 3164 KB Output is correct
20 Correct 163 ms 3300 KB Output is correct
21 Correct 166 ms 3152 KB Output is correct
22 Correct 161 ms 3148 KB Output is correct
23 Correct 159 ms 3172 KB Output is correct
24 Correct 167 ms 3148 KB Output is correct
25 Correct 161 ms 3272 KB Output is correct
26 Correct 164 ms 3148 KB Output is correct
27 Correct 164 ms 3156 KB Output is correct
28 Correct 163 ms 3152 KB Output is correct
29 Correct 159 ms 3168 KB Output is correct
30 Correct 160 ms 3156 KB Output is correct
31 Correct 166 ms 3236 KB Output is correct
32 Correct 169 ms 3232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 43 ms 3148 KB Output is correct
8 Correct 48 ms 3148 KB Output is correct
9 Correct 43 ms 3160 KB Output is correct
10 Correct 65 ms 3152 KB Output is correct
11 Correct 64 ms 3264 KB Output is correct
12 Correct 79 ms 3132 KB Output is correct
13 Correct 79 ms 3232 KB Output is correct
14 Correct 48 ms 3268 KB Output is correct
15 Correct 44 ms 3272 KB Output is correct
16 Correct 65 ms 3132 KB Output is correct
17 Correct 71 ms 3200 KB Output is correct
18 Correct 77 ms 3224 KB Output is correct
19 Correct 78 ms 3244 KB Output is correct
20 Correct 159 ms 3168 KB Output is correct
21 Correct 160 ms 3172 KB Output is correct
22 Correct 161 ms 3164 KB Output is correct
23 Correct 165 ms 3156 KB Output is correct
24 Correct 161 ms 3276 KB Output is correct
25 Correct 162 ms 3156 KB Output is correct
26 Correct 160 ms 3164 KB Output is correct
27 Correct 163 ms 3300 KB Output is correct
28 Correct 166 ms 3152 KB Output is correct
29 Correct 161 ms 3148 KB Output is correct
30 Correct 159 ms 3172 KB Output is correct
31 Correct 167 ms 3148 KB Output is correct
32 Correct 161 ms 3272 KB Output is correct
33 Correct 164 ms 3148 KB Output is correct
34 Correct 164 ms 3156 KB Output is correct
35 Correct 163 ms 3152 KB Output is correct
36 Correct 159 ms 3168 KB Output is correct
37 Correct 160 ms 3156 KB Output is correct
38 Correct 166 ms 3236 KB Output is correct
39 Correct 169 ms 3232 KB Output is correct
40 Correct 48 ms 3208 KB Output is correct
41 Incorrect 72 ms 3180 KB Output isn't correct
42 Halted 0 ms 0 KB -