답안 #703971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703971 2023-03-01T07:20:27 Z ancuber1031 Autobus (COCI22_autobus) C++14
0 / 70
2 ms 468 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define p_q priority_queue
#define endl '\n'
#define pb push_back

int n, m;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n>>m;
    vector<vector<int> > g(n+1,vector<int>(n+1,1e18)), dp(n+1,vector<int>(n+1,1e18))
    , cnt(n+1,vector<int>(n+1,0));
    for (int i = 1; i <= n; ++i) dp[i][i] = 0;
    while(m--) {
        int a, b, t;
        cin>>a>>b>>t;
        dp[a][b] = min(t,dp[a][b]);
        cnt[a][b] = 1;
    }
    int k, q; cin>>k>>q;
    for (int l = 1; l <= n; ++l) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (dp[i][j] > dp[i][l]+dp[l][j] && cnt[i][l]+cnt[l][j] <= k) {
                    dp[i][j] = dp[i][l]+dp[l][j];
                    cnt[i][j] = cnt[i][l]+cnt[l][j];
                }
            }
        }
    }
    
    while(q--) {
        int c, d; cin>>c>>d;
        if (dp[c][d] >= 1e18) cout<<-1<<endl;
        else cout<<dp[c][d]<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Incorrect 2 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -