Submission #910864

# Submission time Handle Problem Language Result Execution time Memory
910864 2024-01-18T08:37:29 Z vjudge1 Autobus (COCI22_autobus) C++17
70 / 70
120 ms 10072 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back

#define TASKNAME "NAME"

void init()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}

const int SZ = 75;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;

int n,m,k,q;

struct Edge
{
    int v;
    ll w;
    Edge(int _v = 0, ll _w = 0) : v(_v), w(_w) {}
};

vector<Edge> adj[SZ];
ll d[SZ][SZ][SZ], len[SZ][SZ];
bool vis[SZ][SZ];

void dijkstra(int s)
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= min(k,n); j++)
        {
            d[s][i][j] = INFLL;
        }
    }
    d[s][s][0] = 0;
    for(int i = 1; i <= min(k,n); i++)
    {
        for(int u = 1; u <= n; u++)
        {
            for(Edge e : adj[u])
            {
                int v = e.v;
                ll w = e.w;
                d[s][v][i] = min(d[s][v][i], d[s][u][i-1] + w);
            }
        }
    }
}

int main()
{
    init();
    cin >> n >> m;
    memset(len, -1, sizeof(len));
    for(int i = 1; i <= m; i++)
    {
        int u,v;
        ll w;
        cin >> u >> v >> w;
        if(len[u][v] == -1 || w < len[u][v]) len[u][v] = w;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(i == j || len[i][j] == -1) continue;
            adj[i].pb({j, len[i][j]});
        }
    }
    cin >> k >> q;
    for(int u = 1; u <= n; u++)
    {
        dijkstra(u);
    }
    while(q--)
    {
        int u,v;
        cin >> u >> v;
        ll res = INFLL;
        for(int i = 0; i <= min(k,n); i++)
        {
            res = min(res, d[u][v][i]);
        }
        cout << (res == INFLL ? -1 : res) << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3416 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 2 ms 3660 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 4 ms 3552 KB Output is correct
6 Correct 3 ms 3676 KB Output is correct
7 Correct 4 ms 3600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 4 ms 3676 KB Output is correct
8 Correct 7 ms 3676 KB Output is correct
9 Correct 3 ms 3672 KB Output is correct
10 Correct 7 ms 3420 KB Output is correct
11 Correct 6 ms 3676 KB Output is correct
12 Correct 20 ms 3576 KB Output is correct
13 Correct 74 ms 9704 KB Output is correct
14 Correct 85 ms 9836 KB Output is correct
15 Correct 100 ms 9832 KB Output is correct
16 Correct 86 ms 9812 KB Output is correct
17 Correct 78 ms 10056 KB Output is correct
18 Correct 74 ms 9808 KB Output is correct
19 Correct 115 ms 9808 KB Output is correct
20 Correct 91 ms 9952 KB Output is correct
21 Correct 77 ms 9808 KB Output is correct
22 Correct 83 ms 9808 KB Output is correct
23 Correct 78 ms 9808 KB Output is correct
24 Correct 91 ms 9956 KB Output is correct
25 Correct 84 ms 10072 KB Output is correct
26 Correct 93 ms 9952 KB Output is correct
27 Correct 85 ms 9836 KB Output is correct
28 Correct 94 ms 10068 KB Output is correct
29 Correct 88 ms 9700 KB Output is correct
30 Correct 83 ms 9984 KB Output is correct
31 Correct 93 ms 9808 KB Output is correct
32 Correct 106 ms 9636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 4 ms 3416 KB Output is correct
8 Correct 2 ms 3676 KB Output is correct
9 Correct 2 ms 3660 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 4 ms 3552 KB Output is correct
12 Correct 3 ms 3676 KB Output is correct
13 Correct 4 ms 3600 KB Output is correct
14 Correct 4 ms 3676 KB Output is correct
15 Correct 7 ms 3676 KB Output is correct
16 Correct 3 ms 3672 KB Output is correct
17 Correct 7 ms 3420 KB Output is correct
18 Correct 6 ms 3676 KB Output is correct
19 Correct 20 ms 3576 KB Output is correct
20 Correct 74 ms 9704 KB Output is correct
21 Correct 85 ms 9836 KB Output is correct
22 Correct 100 ms 9832 KB Output is correct
23 Correct 86 ms 9812 KB Output is correct
24 Correct 78 ms 10056 KB Output is correct
25 Correct 74 ms 9808 KB Output is correct
26 Correct 115 ms 9808 KB Output is correct
27 Correct 91 ms 9952 KB Output is correct
28 Correct 77 ms 9808 KB Output is correct
29 Correct 83 ms 9808 KB Output is correct
30 Correct 78 ms 9808 KB Output is correct
31 Correct 91 ms 9956 KB Output is correct
32 Correct 84 ms 10072 KB Output is correct
33 Correct 93 ms 9952 KB Output is correct
34 Correct 85 ms 9836 KB Output is correct
35 Correct 94 ms 10068 KB Output is correct
36 Correct 88 ms 9700 KB Output is correct
37 Correct 83 ms 9984 KB Output is correct
38 Correct 93 ms 9808 KB Output is correct
39 Correct 106 ms 9636 KB Output is correct
40 Correct 3 ms 3676 KB Output is correct
41 Correct 6 ms 3552 KB Output is correct
42 Correct 4 ms 3676 KB Output is correct
43 Correct 11 ms 3676 KB Output is correct
44 Correct 7 ms 3676 KB Output is correct
45 Correct 32 ms 3552 KB Output is correct
46 Correct 74 ms 9712 KB Output is correct
47 Correct 100 ms 9716 KB Output is correct
48 Correct 79 ms 9700 KB Output is correct
49 Correct 111 ms 9828 KB Output is correct
50 Correct 76 ms 9812 KB Output is correct
51 Correct 87 ms 9712 KB Output is correct
52 Correct 72 ms 9868 KB Output is correct
53 Correct 120 ms 9792 KB Output is correct
54 Correct 74 ms 9836 KB Output is correct
55 Correct 85 ms 9808 KB Output is correct
56 Correct 106 ms 9836 KB Output is correct
57 Correct 107 ms 9828 KB Output is correct
58 Correct 75 ms 9968 KB Output is correct
59 Correct 89 ms 10072 KB Output is correct
60 Correct 102 ms 10068 KB Output is correct
61 Correct 119 ms 10072 KB Output is correct
62 Correct 73 ms 9808 KB Output is correct
63 Correct 91 ms 9612 KB Output is correct
64 Correct 83 ms 9628 KB Output is correct
65 Correct 112 ms 9812 KB Output is correct