Submission #699569

# Submission time Handle Problem Language Result Execution time Memory
699569 2023-02-17T12:11:35 Z Gital Autobus (COCI22_autobus) C++11
0 / 70
2 ms 432 KB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

ll dp[71][71];
ll path[71][71];
bool checked[71];
int n,m,k,q;
int a,b,t;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        cin >> a >> b >> t;
        if(path[a][b] == 0 || path[a][b] > t) path[a][b] = t;
    }
    cin >> k >> q;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            dp[i][j] = -1;
            checked[j] = false;
        }
        for(int cnt = 0; cnt < min(k,100); cnt++) {
            dp[i][i] = 0;
            ll minV = LLONG_MAX; ll minIndex = 0;
            for(int j = 1; j <= n; j++) {
                if(dp[i][j] != -1 && !checked[j] && dp[i][j] < minV) {
                    minV = dp[i][j];
                    minIndex = j;
                }
            }
            checked[(int)minIndex] = true;
            for(int j = 1; j <= 70; j++) {
                if(path[minIndex][j] != 0) {
                    if(dp[i][j] == -1 || dp[i][j] > path[minIndex][j] + minV) {
                        dp[i][j] = path[minIndex][j] + minV;
                    }
                }
            }
        }
    }
    for(int i = 0; i < q; i++) {
        cin >> a >> b;
        cout << dp[a][b] << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 2 ms 432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -