Submission #868014

# Submission time Handle Problem Language Result Execution time Memory
868014 2023-10-30T08:18:28 Z SalihSahin Autobus (COCI22_autobus) C++14
0 / 70
1000 ms 3408 KB
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long 
using namespace std;

const int mod = 998244353;
const int N = 2e5 + 5;
const int inf = 1e12 + 5;


int32_t main(){
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin>>n>>m;
    int dis[n][n][n+1];
    int edge[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            edge[i][j] = inf;
            for(int k = 0; k < n; k++){
                dis[i][j][k] = inf;
            }
        }
    }

    for(int i = 0; i < m; i++){
        int a, b, c;
        cin>>a>>b>>c;
        a--, b--;
        edge[a][b] = min(edge[a][b], c);
    }

    for(int i = 0; i < n; i++){
        dis[i][i][0] = 0;
        for(int j = 0; j < n; j++){
            dis[i][j][1] = edge[i][j];
        }
    }

    for(int len = 2; len <= n; len++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < n; k++){
                    for(int lenf = 1; lenf < len; lenf++){
                        dis[i][j][len] = min(dis[i][j][len], dis[i][k][lenf] + dis[k][j][len - lenf]);
                    }
                }
            }
        }
    }

    int mndis[n][n];

    int k, q;
    cin>>k>>q;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int ans = inf;
            for(int len = 0; len <= min(n, k); len++){
                ans = min(ans, dis[i][j][len]);
            }
            mndis[i][j] = ans;
        }
    }

    while(q--){
        int a, b;
        cin>>a>>b;
        if(mndis[a-1][b-1] < inf) cout<<mndis[a-1][b-1]<<endl;
        else cout<<-1<<endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 984 ms 3188 KB Output is correct
2 Correct 973 ms 3408 KB Output is correct
3 Correct 980 ms 3188 KB Output is correct
4 Execution timed out 1006 ms 3240 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -