Submission #631601

# Submission time Handle Problem Language Result Execution time Memory
631601 2022-08-18T09:43:10 Z GudStonks Autobus (COCI22_autobus) C++17
70 / 70
479 ms 9752 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m, k, q, d[75][75][75];
void fun()
{
    cin>>n>>m;
    for(ll i = 1; i <= n; i++)
        for(ll j = 1; j <= n; j++)
            for(ll l = 0; l <= n + 1; l++)
                d[i][j][l] = 2e18;
    for(ll i = 1, a, b, c; i <= m; i++)
    {
        cin>>a>>b>>c;
        d[a][b][1] = min(d[a][b][1], c);
    }
    cin>>k>>q;
    k = min(k, n);
    for(ll v = 1; v <= n; v++)
        for(ll i = 1; i <= n; i++)
            for(ll j = 1; j <= n; j++)
                for(ll l = 1; l <= n; l++)
                    if(d[i][l][v - 1] != 2e18 && d[l][j][1] != 2e18)
                        d[i][j][v] = min(d[i][j][v], d[i][l][v - 1] + d[l][j][1]);
    for(ll i = 1, a, b; i <= q; i++)
    {
        cin>>a>>b;
        if(a == b)
        {
            cout<<0<<endl;
            continue;
        }
        ll ans = 2e18;
        for(int j = 1; j <= k; j++)
            ans = min(ans, d[a][b][j]);
        if(ans == 2e18)
            cout<<-1<<endl;
        else
            cout<<ans<<endl;
    }
}

int main()
{
	ll ttt = 1;
	//cin>>ttt;
	while(ttt--)
		fun();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 3372 KB Output is correct
2 Correct 104 ms 3364 KB Output is correct
3 Correct 96 ms 3412 KB Output is correct
4 Correct 120 ms 3412 KB Output is correct
5 Correct 127 ms 3412 KB Output is correct
6 Correct 139 ms 3444 KB Output is correct
7 Correct 117 ms 3460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 96 ms 3400 KB Output is correct
8 Correct 101 ms 3412 KB Output is correct
9 Correct 126 ms 3412 KB Output is correct
10 Correct 116 ms 3412 KB Output is correct
11 Correct 143 ms 3448 KB Output is correct
12 Correct 117 ms 3460 KB Output is correct
13 Correct 395 ms 9492 KB Output is correct
14 Correct 373 ms 9492 KB Output is correct
15 Correct 397 ms 9620 KB Output is correct
16 Correct 372 ms 9504 KB Output is correct
17 Correct 440 ms 9576 KB Output is correct
18 Correct 381 ms 9548 KB Output is correct
19 Correct 400 ms 9488 KB Output is correct
20 Correct 391 ms 9700 KB Output is correct
21 Correct 394 ms 9604 KB Output is correct
22 Correct 372 ms 9624 KB Output is correct
23 Correct 384 ms 9636 KB Output is correct
24 Correct 454 ms 9616 KB Output is correct
25 Correct 397 ms 9696 KB Output is correct
26 Correct 393 ms 9676 KB Output is correct
27 Correct 405 ms 9744 KB Output is correct
28 Correct 403 ms 9620 KB Output is correct
29 Correct 387 ms 9440 KB Output is correct
30 Correct 382 ms 9452 KB Output is correct
31 Correct 379 ms 9492 KB Output is correct
32 Correct 382 ms 9440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 135 ms 3372 KB Output is correct
8 Correct 104 ms 3364 KB Output is correct
9 Correct 96 ms 3412 KB Output is correct
10 Correct 120 ms 3412 KB Output is correct
11 Correct 127 ms 3412 KB Output is correct
12 Correct 139 ms 3444 KB Output is correct
13 Correct 117 ms 3460 KB Output is correct
14 Correct 96 ms 3400 KB Output is correct
15 Correct 101 ms 3412 KB Output is correct
16 Correct 126 ms 3412 KB Output is correct
17 Correct 116 ms 3412 KB Output is correct
18 Correct 143 ms 3448 KB Output is correct
19 Correct 117 ms 3460 KB Output is correct
20 Correct 395 ms 9492 KB Output is correct
21 Correct 373 ms 9492 KB Output is correct
22 Correct 397 ms 9620 KB Output is correct
23 Correct 372 ms 9504 KB Output is correct
24 Correct 440 ms 9576 KB Output is correct
25 Correct 381 ms 9548 KB Output is correct
26 Correct 400 ms 9488 KB Output is correct
27 Correct 391 ms 9700 KB Output is correct
28 Correct 394 ms 9604 KB Output is correct
29 Correct 372 ms 9624 KB Output is correct
30 Correct 384 ms 9636 KB Output is correct
31 Correct 454 ms 9616 KB Output is correct
32 Correct 397 ms 9696 KB Output is correct
33 Correct 393 ms 9676 KB Output is correct
34 Correct 405 ms 9744 KB Output is correct
35 Correct 403 ms 9620 KB Output is correct
36 Correct 387 ms 9440 KB Output is correct
37 Correct 382 ms 9452 KB Output is correct
38 Correct 379 ms 9492 KB Output is correct
39 Correct 382 ms 9440 KB Output is correct
40 Correct 102 ms 3412 KB Output is correct
41 Correct 104 ms 3432 KB Output is correct
42 Correct 122 ms 3412 KB Output is correct
43 Correct 123 ms 3412 KB Output is correct
44 Correct 116 ms 3452 KB Output is correct
45 Correct 116 ms 3444 KB Output is correct
46 Correct 392 ms 9420 KB Output is correct
47 Correct 376 ms 9628 KB Output is correct
48 Correct 382 ms 9548 KB Output is correct
49 Correct 385 ms 9492 KB Output is correct
50 Correct 421 ms 9576 KB Output is correct
51 Correct 379 ms 9492 KB Output is correct
52 Correct 479 ms 9576 KB Output is correct
53 Correct 399 ms 9572 KB Output is correct
54 Correct 438 ms 9616 KB Output is correct
55 Correct 382 ms 9620 KB Output is correct
56 Correct 387 ms 9600 KB Output is correct
57 Correct 397 ms 9612 KB Output is correct
58 Correct 395 ms 9700 KB Output is correct
59 Correct 406 ms 9748 KB Output is correct
60 Correct 391 ms 9632 KB Output is correct
61 Correct 381 ms 9752 KB Output is correct
62 Correct 400 ms 9372 KB Output is correct
63 Correct 388 ms 9440 KB Output is correct
64 Correct 423 ms 9440 KB Output is correct
65 Correct 386 ms 9436 KB Output is correct