Submission #699302

# Submission time Handle Problem Language Result Execution time Memory
699302 2023-02-16T14:04:35 Z Gital Autobus (COCI22_autobus) C++11
15 / 70
1000 ms 328648 KB
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

priority_queue<pair<pair<ll,ll>,pair<vector<bool>,int>>,vector<pair<pair<ll,ll>,pair<vector<bool>,int>>>,greater<pair<pair<ll,ll>,pair<vector<bool>,int>>>> pq;
ll dp[71][71];
ll path[71][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++) {
        vector<bool> temp(71,false);
        for(int j = 1; j <= 70; j++) {
            dp[i][j] = -1;
        }
        dp[i][i] = 0;
        pq.push({{0,i},{temp,0}});
        while(!pq.empty()) {
            ll a = pq.top().first.first;
            ll b = pq.top().first.second;
            vector<bool> checked = pq.top().second.first;
            int cnt = pq.top().second.second;
            pq.pop();
            if(cnt >= k) continue;
            if(checked[b]) continue;
            checked[b] = true;
            for(int j = 1; j <= n; j++) {
                if(path[b][j] != 0 && !checked[j]) {
                    pq.push({{a + path[b][j],j},{checked,cnt+1}});
                    if(dp[i][j] == -1 || dp[i][j] > a + path[b][j]) {
                        dp[i][j] = a + path[b][j];
                    }
                }
            }
        }
    }
    for(int i = 0; i < q; i++) {
        cin >> a >> b;
        cout << dp[a][b] << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 7 ms 452 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 89 ms 660 KB Output is correct
6 Correct 49 ms 584 KB Output is correct
7 Execution timed out 1091 ms 5532 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Execution timed out 1103 ms 328648 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 7 ms 452 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 89 ms 660 KB Output is correct
12 Correct 49 ms 584 KB Output is correct
13 Execution timed out 1091 ms 5532 KB Time limit exceeded
14 Halted 0 ms 0 KB -