Submission #639266

# Submission time Handle Problem Language Result Execution time Memory
639266 2022-09-09T07:18:40 Z NotLinux Autobus (COCI22_autobus) C++14
0 / 70
8 ms 580 KB
/**
 * author: NotLinux
 * created: 09.09.2022 ~ 09:52:25
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
    #include "/home/notlinux/debug.h"
#else
    #define debug(x...) void(37)
#endif
int n,m;
const int inf = 1e15;
vector<vector<int>> opr(vector<vector<int>>a , vector<vector<int>>b){
    vector<vector<int>>c(n , vector < int > (n,inf));
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            for(int k = 0;k<n;k++){
                c[i][k] = min(c[i][k] , a[i][j] + b[j][k]);
            }
        }
    }
    return c;
}
void solve(){
    cin >> n >> m;
    vector < vector < int > > graph(n , vector < int > (n,inf));
    for(int i = 0;i<m;i++){
        int a,b,t;cin >> a >> b >> t;
        graph[a-1][b-1] = t;
    }
    for(int i = 0;i<n;i++)graph[i][i] = 0;
    int k,q;cin >> k >> q;
    k = min(k , (n*n-n)/2);
    vector < vector < vector < int > > > past;
    for(int i = 0;i<k;i++){
        past.push_back(graph);
        graph = opr(graph , graph);
    }
    /*cout << "past : " << endl;
    for(int z = 0;z<k;z++){
        for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++){
                cout << past[z][i][j] << " ";
            }
            cout << endl;
        }
        cout << "------------" << endl;
    }*/
    vector < vector < int > > ans(n , vector < int > (n,inf));
    for(int i = 0;i<n;i++)for(int j = 0;j<n;j++)for(int z = 0;z<k;z++){
        ans[i][j] = min(ans[i][j] , past[z][i][j]);
    }
    /*cout << "ans : " << endl;
    for(int i = 0;i<n;i++){
            for(int j = 0;j<n;j++){
                cout << ans[i][j] << " ";
            }
            cout << endl;
        }*/
    while(q--){
        int l,r;cin >> l >> r;
        cout << (ans[l-1][r-1]==inf ? -1 : ans[l-1][r-1]) << endl;
    }
}
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    int tt=1;
 //   cin >> tt;
    while(tt--)solve();
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -