Submission #696620

# Submission time Handle Problem Language Result Execution time Memory
696620 2023-02-07T01:36:14 Z anhduc2701 Autobus (COCI22_autobus) C++17
70 / 70
123 ms 4136 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"  
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m;
int f[71][71][71];
int dis[71][71];
signed main()
{
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    //freopen(task".inp" , "r" , stdin);
    //freopen(task".out" , "w" , stdout);
   	cin>>n>>m;
   	for(int i=1;i<=n;i++){
   		for(int j=1;j<=n;j++){
   			dis[i][j]=INF;
   		}
   	}
   	for(int i=1;i<=m;i++){
   		int a,b,t;
   		cin>>a>>b>>t;
   		dis[a][b]=min(dis[a][b],t);
   	}

   	int k,q;
   	cin>>k>>q;
   	for(int i=1;i<=n;i++){
   		for(int j=1;j<=n;j++){
   			if(i==j)f[i][j][0]=0;
   			else f[i][j][0]=INF;
   		}
   	}
   	for(int i=1;i<=min(n,k);i++){
   		for(int j=1;j<=n;j++){
   			for(int z=1;z<=n;z++){
   				f[j][z][i]=f[j][z][i-1];
   			}
   		}
		for(int j=1;j<=n;j++){
			for(int z=1;z<=n;z++){
				for(int k=1;k<=n;k++){
					f[j][k][i]=min(f[j][z][i-1]+dis[z][k],f[j][k][i]);
				}
			}
		}	
   	}
   	while(q--){
   		int c,d;
   		cin>>c>>d;
   		if(f[c][d][min(n,k)]==INF){
   			cout<<-1<<"\n";
   		}
   		else{
   			cout<<f[c][d][min(n,k)]<<"\n";
   		}
   	}
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3176 KB Output is correct
2 Correct 5 ms 3156 KB Output is correct
3 Correct 5 ms 3168 KB Output is correct
4 Correct 6 ms 3156 KB Output is correct
5 Correct 4 ms 3160 KB Output is correct
6 Correct 5 ms 3160 KB Output is correct
7 Correct 5 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 11 ms 3156 KB Output is correct
8 Correct 26 ms 3160 KB Output is correct
9 Correct 4 ms 3160 KB Output is correct
10 Correct 16 ms 3168 KB Output is correct
11 Correct 7 ms 3144 KB Output is correct
12 Correct 18 ms 3200 KB Output is correct
13 Correct 89 ms 3808 KB Output is correct
14 Correct 99 ms 3764 KB Output is correct
15 Correct 104 ms 3864 KB Output is correct
16 Correct 90 ms 3812 KB Output is correct
17 Correct 92 ms 3820 KB Output is correct
18 Correct 92 ms 3804 KB Output is correct
19 Correct 108 ms 3776 KB Output is correct
20 Correct 107 ms 3872 KB Output is correct
21 Correct 98 ms 3852 KB Output is correct
22 Correct 95 ms 3872 KB Output is correct
23 Correct 91 ms 3796 KB Output is correct
24 Correct 96 ms 3788 KB Output is correct
25 Correct 103 ms 3796 KB Output is correct
26 Correct 110 ms 3884 KB Output is correct
27 Correct 94 ms 3836 KB Output is correct
28 Correct 94 ms 3888 KB Output is correct
29 Correct 104 ms 3872 KB Output is correct
30 Correct 93 ms 3924 KB Output is correct
31 Correct 94 ms 3812 KB Output is correct
32 Correct 115 ms 3884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 3 ms 3176 KB Output is correct
8 Correct 5 ms 3156 KB Output is correct
9 Correct 5 ms 3168 KB Output is correct
10 Correct 6 ms 3156 KB Output is correct
11 Correct 4 ms 3160 KB Output is correct
12 Correct 5 ms 3160 KB Output is correct
13 Correct 5 ms 3160 KB Output is correct
14 Correct 11 ms 3156 KB Output is correct
15 Correct 26 ms 3160 KB Output is correct
16 Correct 4 ms 3160 KB Output is correct
17 Correct 16 ms 3168 KB Output is correct
18 Correct 7 ms 3144 KB Output is correct
19 Correct 18 ms 3200 KB Output is correct
20 Correct 89 ms 3808 KB Output is correct
21 Correct 99 ms 3764 KB Output is correct
22 Correct 104 ms 3864 KB Output is correct
23 Correct 90 ms 3812 KB Output is correct
24 Correct 92 ms 3820 KB Output is correct
25 Correct 92 ms 3804 KB Output is correct
26 Correct 108 ms 3776 KB Output is correct
27 Correct 107 ms 3872 KB Output is correct
28 Correct 98 ms 3852 KB Output is correct
29 Correct 95 ms 3872 KB Output is correct
30 Correct 91 ms 3796 KB Output is correct
31 Correct 96 ms 3788 KB Output is correct
32 Correct 103 ms 3796 KB Output is correct
33 Correct 110 ms 3884 KB Output is correct
34 Correct 94 ms 3836 KB Output is correct
35 Correct 94 ms 3888 KB Output is correct
36 Correct 104 ms 3872 KB Output is correct
37 Correct 93 ms 3924 KB Output is correct
38 Correct 94 ms 3812 KB Output is correct
39 Correct 115 ms 3884 KB Output is correct
40 Correct 8 ms 3168 KB Output is correct
41 Correct 33 ms 3156 KB Output is correct
42 Correct 6 ms 3160 KB Output is correct
43 Correct 31 ms 3156 KB Output is correct
44 Correct 7 ms 3212 KB Output is correct
45 Correct 27 ms 3204 KB Output is correct
46 Correct 88 ms 3816 KB Output is correct
47 Correct 96 ms 3880 KB Output is correct
48 Correct 90 ms 3832 KB Output is correct
49 Correct 108 ms 3924 KB Output is correct
50 Correct 87 ms 3808 KB Output is correct
51 Correct 96 ms 3920 KB Output is correct
52 Correct 98 ms 3860 KB Output is correct
53 Correct 115 ms 4048 KB Output is correct
54 Correct 89 ms 4032 KB Output is correct
55 Correct 96 ms 4044 KB Output is correct
56 Correct 109 ms 4136 KB Output is correct
57 Correct 114 ms 4060 KB Output is correct
58 Correct 104 ms 4064 KB Output is correct
59 Correct 106 ms 4072 KB Output is correct
60 Correct 123 ms 4128 KB Output is correct
61 Correct 121 ms 4068 KB Output is correct
62 Correct 88 ms 4088 KB Output is correct
63 Correct 97 ms 3184 KB Output is correct
64 Correct 89 ms 3044 KB Output is correct
65 Correct 116 ms 3040 KB Output is correct