답안 #699298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699298 2023-02-16T14:00:18 Z Gital Autobus (COCI22_autobus) C++11
15 / 70
1000 ms 328780 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) {
                    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 7 ms 468 KB Output is correct
4 Correct 6 ms 468 KB Output is correct
5 Correct 85 ms 836 KB Output is correct
6 Correct 43 ms 580 KB Output is correct
7 Execution timed out 1081 ms 5544 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Execution timed out 1091 ms 328780 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 340 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 468 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 85 ms 836 KB Output is correct
12 Correct 43 ms 580 KB Output is correct
13 Execution timed out 1081 ms 5544 KB Time limit exceeded
14 Halted 0 ms 0 KB -