이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |