답안 #959023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959023 2024-04-07T11:42:45 Z MilosMilutinovic Autobus (COCI22_autobus) C++14
70 / 70
66 ms 8364 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,k,q;
int d[75][75],dp[75][75][75],res[75][75];

int main(){
	n=readint(); m=readint();
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=1e9;
	for(int i=1;i<=m;i++){
		int u=readint(),v=readint(),w=readint();
		chkmin(d[u][v],w);
	}
	k=readint(); q=readint();
	for(int t=0;t<=min(n,k);t++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dp[t][i][j]=1e9;
			}
		}
	}
	for(int i=1;i<=n;i++) dp[0][i][i]=0;
	for(int t=1;t<=min(k,n);t++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int r=1;r<=n;r++){
					chkmin(dp[t][i][r],dp[t-1][i][j]+d[j][r]);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			res[i][j]=1e9;
			for(int t=0;t<=min(n,k);t++){
				chkmin(res[i][j],dp[t][i][j]);
			}
		}
	}
	while(q--){
		int x=readint(),y=readint();
		if(res[x][y]==1e9) printf("-1\n");
		else printf("%d\n",res[x][y]);
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 16 ms 860 KB Output is correct
8 Correct 30 ms 1884 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 16 ms 1372 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 21 ms 1372 KB Output is correct
13 Correct 29 ms 6708 KB Output is correct
14 Correct 27 ms 6576 KB Output is correct
15 Correct 46 ms 7872 KB Output is correct
16 Correct 38 ms 6948 KB Output is correct
17 Correct 27 ms 6788 KB Output is correct
18 Correct 23 ms 6572 KB Output is correct
19 Correct 53 ms 8212 KB Output is correct
20 Correct 42 ms 7476 KB Output is correct
21 Correct 23 ms 6736 KB Output is correct
22 Correct 28 ms 6992 KB Output is correct
23 Correct 28 ms 6972 KB Output is correct
24 Correct 46 ms 7464 KB Output is correct
25 Correct 25 ms 6704 KB Output is correct
26 Correct 31 ms 6996 KB Output is correct
27 Correct 33 ms 7328 KB Output is correct
28 Correct 31 ms 6996 KB Output is correct
29 Correct 25 ms 6708 KB Output is correct
30 Correct 30 ms 6924 KB Output is correct
31 Correct 40 ms 7260 KB Output is correct
32 Correct 59 ms 8092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 544 KB Output is correct
14 Correct 16 ms 860 KB Output is correct
15 Correct 30 ms 1884 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 16 ms 1372 KB Output is correct
18 Correct 6 ms 604 KB Output is correct
19 Correct 21 ms 1372 KB Output is correct
20 Correct 29 ms 6708 KB Output is correct
21 Correct 27 ms 6576 KB Output is correct
22 Correct 46 ms 7872 KB Output is correct
23 Correct 38 ms 6948 KB Output is correct
24 Correct 27 ms 6788 KB Output is correct
25 Correct 23 ms 6572 KB Output is correct
26 Correct 53 ms 8212 KB Output is correct
27 Correct 42 ms 7476 KB Output is correct
28 Correct 23 ms 6736 KB Output is correct
29 Correct 28 ms 6992 KB Output is correct
30 Correct 28 ms 6972 KB Output is correct
31 Correct 46 ms 7464 KB Output is correct
32 Correct 25 ms 6704 KB Output is correct
33 Correct 31 ms 6996 KB Output is correct
34 Correct 33 ms 7328 KB Output is correct
35 Correct 31 ms 6996 KB Output is correct
36 Correct 25 ms 6708 KB Output is correct
37 Correct 30 ms 6924 KB Output is correct
38 Correct 40 ms 7260 KB Output is correct
39 Correct 59 ms 8092 KB Output is correct
40 Correct 9 ms 860 KB Output is correct
41 Correct 30 ms 2064 KB Output is correct
42 Correct 5 ms 604 KB Output is correct
43 Correct 32 ms 2056 KB Output is correct
44 Correct 5 ms 756 KB Output is correct
45 Correct 31 ms 2000 KB Output is correct
46 Correct 25 ms 6584 KB Output is correct
47 Correct 43 ms 7372 KB Output is correct
48 Correct 31 ms 6976 KB Output is correct
49 Correct 52 ms 8020 KB Output is correct
50 Correct 26 ms 6580 KB Output is correct
51 Correct 30 ms 6996 KB Output is correct
52 Correct 26 ms 6736 KB Output is correct
53 Correct 53 ms 8116 KB Output is correct
54 Correct 25 ms 6828 KB Output is correct
55 Correct 25 ms 6744 KB Output is correct
56 Correct 54 ms 8364 KB Output is correct
57 Correct 54 ms 8300 KB Output is correct
58 Correct 25 ms 6740 KB Output is correct
59 Correct 36 ms 7512 KB Output is correct
60 Correct 54 ms 8132 KB Output is correct
61 Correct 53 ms 8268 KB Output is correct
62 Correct 25 ms 6480 KB Output is correct
63 Correct 35 ms 6956 KB Output is correct
64 Correct 34 ms 7064 KB Output is correct
65 Correct 66 ms 8096 KB Output is correct