답안 #696621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696621 2023-02-07T01:41:46 Z Tuanlinh123 Autobus (COCI22_autobus) C++17
70 / 70
118 ms 4556 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ppll pair<ll, pll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

#define LOCALIO "C:/Users/admin/Documents/Code/"

ll A[100][100];
ll dp[100][100][100];

int main()
{
    #ifdef LOCAL
        freopen( LOCALIO "input.txt","r",stdin) ;
        freopen( LOCALIO "output.txt","w",stdout) ;
    #endif

    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
//	freopen("FIBONACCI.inp","r",stdin);
//	freopen("FIBONACCI.out","w",stdout);
    ll n, m; cin >> n >> m;
    for (ll i=1; i<=n; i++)
        for (ll j=1; j<=n; j++)
        {
            A[i][j]=1e18;
            for (ll k=0; k<=n; k++)
                dp[i][j][k]=1e18;
        }
    for (ll i=1; i<=m; i++)
    {
        ll u, v, w; cin >> u >> v >> w;
        A[u][v]=min(A[u][v], w);
    }
    for (ll i=1; i<=n; i++)
        dp[i][i][0]=0;
    for (ll i=1; i<=n; i++)
        for (ll j=1; j<=n; j++)
            for (ll k=1; k<=n; k++)
                for (ll z=1; z<=n; z++)
                    dp[j][k][i]=min(dp[j][k][i], dp[j][z][i-1]+A[z][k]);
    ll k, q; cin >> k >> q;
    for (ll i=1; i<=q; i++)
    {
        ll u, v; cin >> u >> v;
        ll ans=1e18;
        for (ll j=0; j<=min(k, n); j++)
            ans=min(ans, dp[u][v][j]);
        if (ans>1e17)
            cout << -1;
        else cout << ans;
        cout << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4436 KB Output is correct
2 Correct 29 ms 4436 KB Output is correct
3 Correct 30 ms 4484 KB Output is correct
4 Correct 30 ms 4496 KB Output is correct
5 Correct 29 ms 4484 KB Output is correct
6 Correct 30 ms 4468 KB Output is correct
7 Correct 32 ms 4484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 30 ms 4496 KB Output is correct
8 Correct 31 ms 4436 KB Output is correct
9 Correct 29 ms 4436 KB Output is correct
10 Correct 30 ms 4480 KB Output is correct
11 Correct 30 ms 4496 KB Output is correct
12 Correct 30 ms 4488 KB Output is correct
13 Correct 112 ms 4472 KB Output is correct
14 Correct 105 ms 4484 KB Output is correct
15 Correct 107 ms 4472 KB Output is correct
16 Correct 109 ms 4488 KB Output is correct
17 Correct 109 ms 4488 KB Output is correct
18 Correct 108 ms 4472 KB Output is correct
19 Correct 108 ms 4472 KB Output is correct
20 Correct 112 ms 4556 KB Output is correct
21 Correct 108 ms 4556 KB Output is correct
22 Correct 108 ms 4472 KB Output is correct
23 Correct 117 ms 4556 KB Output is correct
24 Correct 114 ms 4476 KB Output is correct
25 Correct 111 ms 4484 KB Output is correct
26 Correct 112 ms 4556 KB Output is correct
27 Correct 113 ms 4472 KB Output is correct
28 Correct 111 ms 4484 KB Output is correct
29 Correct 109 ms 4556 KB Output is correct
30 Correct 107 ms 4472 KB Output is correct
31 Correct 108 ms 4488 KB Output is correct
32 Correct 107 ms 4484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 30 ms 4436 KB Output is correct
8 Correct 29 ms 4436 KB Output is correct
9 Correct 30 ms 4484 KB Output is correct
10 Correct 30 ms 4496 KB Output is correct
11 Correct 29 ms 4484 KB Output is correct
12 Correct 30 ms 4468 KB Output is correct
13 Correct 32 ms 4484 KB Output is correct
14 Correct 30 ms 4496 KB Output is correct
15 Correct 31 ms 4436 KB Output is correct
16 Correct 29 ms 4436 KB Output is correct
17 Correct 30 ms 4480 KB Output is correct
18 Correct 30 ms 4496 KB Output is correct
19 Correct 30 ms 4488 KB Output is correct
20 Correct 112 ms 4472 KB Output is correct
21 Correct 105 ms 4484 KB Output is correct
22 Correct 107 ms 4472 KB Output is correct
23 Correct 109 ms 4488 KB Output is correct
24 Correct 109 ms 4488 KB Output is correct
25 Correct 108 ms 4472 KB Output is correct
26 Correct 108 ms 4472 KB Output is correct
27 Correct 112 ms 4556 KB Output is correct
28 Correct 108 ms 4556 KB Output is correct
29 Correct 108 ms 4472 KB Output is correct
30 Correct 117 ms 4556 KB Output is correct
31 Correct 114 ms 4476 KB Output is correct
32 Correct 111 ms 4484 KB Output is correct
33 Correct 112 ms 4556 KB Output is correct
34 Correct 113 ms 4472 KB Output is correct
35 Correct 111 ms 4484 KB Output is correct
36 Correct 109 ms 4556 KB Output is correct
37 Correct 107 ms 4472 KB Output is correct
38 Correct 108 ms 4488 KB Output is correct
39 Correct 107 ms 4484 KB Output is correct
40 Correct 30 ms 4484 KB Output is correct
41 Correct 30 ms 4488 KB Output is correct
42 Correct 28 ms 4436 KB Output is correct
43 Correct 30 ms 4484 KB Output is correct
44 Correct 29 ms 4436 KB Output is correct
45 Correct 30 ms 4484 KB Output is correct
46 Correct 107 ms 4484 KB Output is correct
47 Correct 107 ms 4480 KB Output is correct
48 Correct 106 ms 4484 KB Output is correct
49 Correct 115 ms 4484 KB Output is correct
50 Correct 111 ms 4556 KB Output is correct
51 Correct 111 ms 4436 KB Output is correct
52 Correct 110 ms 4480 KB Output is correct
53 Correct 109 ms 4468 KB Output is correct
54 Correct 108 ms 4436 KB Output is correct
55 Correct 110 ms 4480 KB Output is correct
56 Correct 111 ms 4476 KB Output is correct
57 Correct 108 ms 4472 KB Output is correct
58 Correct 118 ms 4468 KB Output is correct
59 Correct 112 ms 4436 KB Output is correct
60 Correct 109 ms 4480 KB Output is correct
61 Correct 109 ms 4484 KB Output is correct
62 Correct 112 ms 4484 KB Output is correct
63 Correct 111 ms 4468 KB Output is correct
64 Correct 107 ms 4436 KB Output is correct
65 Correct 107 ms 4484 KB Output is correct