답안 #531589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531589 2022-03-01T04:43:53 Z errorgorn Autobus (COCI22_autobus) C++17
70 / 70
187 ms 9588 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m,q,k;
int w[75][75];
int dist[75][75][75];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>m;
	
	memset(w,1,sizeof(w));
	memset(dist,1,sizeof(dist));
	
	rep(x,0,75) dist[0][x][x]=0,w[x][x]=0;
	
	int a,b,c;
	
	rep(x,0,m){
		cin>>a>>b>>c;
		a--,b--;
		w[a][b]=min(w[a][b],c);
	}
	
	rep(i,0,74) rep(x,0,n) rep(y,0,n) rep(z,0,n){
		dist[i+1][x][z]=min(dist[i+1][x][z],dist[i][x][y]+w[y][z]);
	}
	
	cin>>k>>q;
	k=min(k,n);
	
	while (q--){
		cin>>a>>b;
		a--,b--;
		
		cout<<(dist[k][a][b]>1e9?-1:dist[k][a][b])<<endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3660 KB Output is correct
2 Correct 2 ms 3660 KB Output is correct
3 Correct 2 ms 3588 KB Output is correct
4 Correct 2 ms 3660 KB Output is correct
5 Correct 2 ms 3660 KB Output is correct
6 Correct 2 ms 3648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 3660 KB Output is correct
2 Correct 50 ms 3660 KB Output is correct
3 Correct 50 ms 3660 KB Output is correct
4 Correct 53 ms 3652 KB Output is correct
5 Correct 52 ms 3664 KB Output is correct
6 Correct 50 ms 3660 KB Output is correct
7 Correct 48 ms 3660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3660 KB Output is correct
2 Correct 2 ms 3660 KB Output is correct
3 Correct 2 ms 3588 KB Output is correct
4 Correct 2 ms 3660 KB Output is correct
5 Correct 2 ms 3660 KB Output is correct
6 Correct 2 ms 3648 KB Output is correct
7 Correct 50 ms 3668 KB Output is correct
8 Correct 55 ms 3660 KB Output is correct
9 Correct 62 ms 3660 KB Output is correct
10 Correct 54 ms 3648 KB Output is correct
11 Correct 48 ms 3688 KB Output is correct
12 Correct 47 ms 3660 KB Output is correct
13 Correct 161 ms 4500 KB Output is correct
14 Correct 150 ms 4548 KB Output is correct
15 Correct 132 ms 4852 KB Output is correct
16 Correct 153 ms 9172 KB Output is correct
17 Correct 187 ms 5312 KB Output is correct
18 Correct 135 ms 5316 KB Output is correct
19 Correct 143 ms 4808 KB Output is correct
20 Correct 145 ms 5568 KB Output is correct
21 Correct 157 ms 5160 KB Output is correct
22 Correct 144 ms 7592 KB Output is correct
23 Correct 154 ms 3660 KB Output is correct
24 Correct 150 ms 6504 KB Output is correct
25 Correct 150 ms 7320 KB Output is correct
26 Correct 174 ms 3660 KB Output is correct
27 Correct 132 ms 3648 KB Output is correct
28 Correct 139 ms 3660 KB Output is correct
29 Correct 148 ms 3672 KB Output is correct
30 Correct 151 ms 7912 KB Output is correct
31 Correct 132 ms 9588 KB Output is correct
32 Correct 155 ms 9164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3660 KB Output is correct
2 Correct 2 ms 3660 KB Output is correct
3 Correct 2 ms 3588 KB Output is correct
4 Correct 2 ms 3660 KB Output is correct
5 Correct 2 ms 3660 KB Output is correct
6 Correct 2 ms 3648 KB Output is correct
7 Correct 48 ms 3660 KB Output is correct
8 Correct 50 ms 3660 KB Output is correct
9 Correct 50 ms 3660 KB Output is correct
10 Correct 53 ms 3652 KB Output is correct
11 Correct 52 ms 3664 KB Output is correct
12 Correct 50 ms 3660 KB Output is correct
13 Correct 48 ms 3660 KB Output is correct
14 Correct 50 ms 3668 KB Output is correct
15 Correct 55 ms 3660 KB Output is correct
16 Correct 62 ms 3660 KB Output is correct
17 Correct 54 ms 3648 KB Output is correct
18 Correct 48 ms 3688 KB Output is correct
19 Correct 47 ms 3660 KB Output is correct
20 Correct 161 ms 4500 KB Output is correct
21 Correct 150 ms 4548 KB Output is correct
22 Correct 132 ms 4852 KB Output is correct
23 Correct 153 ms 9172 KB Output is correct
24 Correct 187 ms 5312 KB Output is correct
25 Correct 135 ms 5316 KB Output is correct
26 Correct 143 ms 4808 KB Output is correct
27 Correct 145 ms 5568 KB Output is correct
28 Correct 157 ms 5160 KB Output is correct
29 Correct 144 ms 7592 KB Output is correct
30 Correct 154 ms 3660 KB Output is correct
31 Correct 150 ms 6504 KB Output is correct
32 Correct 150 ms 7320 KB Output is correct
33 Correct 174 ms 3660 KB Output is correct
34 Correct 132 ms 3648 KB Output is correct
35 Correct 139 ms 3660 KB Output is correct
36 Correct 148 ms 3672 KB Output is correct
37 Correct 151 ms 7912 KB Output is correct
38 Correct 132 ms 9588 KB Output is correct
39 Correct 155 ms 9164 KB Output is correct
40 Correct 51 ms 3664 KB Output is correct
41 Correct 50 ms 3652 KB Output is correct
42 Correct 48 ms 3772 KB Output is correct
43 Correct 52 ms 3660 KB Output is correct
44 Correct 50 ms 3712 KB Output is correct
45 Correct 54 ms 3656 KB Output is correct
46 Correct 136 ms 4448 KB Output is correct
47 Correct 144 ms 7024 KB Output is correct
48 Correct 141 ms 5484 KB Output is correct
49 Correct 149 ms 8904 KB Output is correct
50 Correct 154 ms 7648 KB Output is correct
51 Correct 154 ms 8016 KB Output is correct
52 Correct 172 ms 8900 KB Output is correct
53 Correct 136 ms 7868 KB Output is correct
54 Correct 133 ms 4588 KB Output is correct
55 Correct 160 ms 6792 KB Output is correct
56 Correct 134 ms 9412 KB Output is correct
57 Correct 140 ms 6236 KB Output is correct
58 Correct 147 ms 3688 KB Output is correct
59 Correct 130 ms 3700 KB Output is correct
60 Correct 131 ms 3660 KB Output is correct
61 Correct 143 ms 3784 KB Output is correct
62 Correct 137 ms 3744 KB Output is correct
63 Correct 131 ms 3668 KB Output is correct
64 Correct 133 ms 3760 KB Output is correct
65 Correct 163 ms 7248 KB Output is correct