Submission #959023

#TimeUsernameProblemLanguageResultExecution timeMemory
959023MilosMilutinovicAutobus (COCI22_autobus)C++14
70 / 70
66 ms8364 KiB
#include<bits/stdc++.h> #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;} template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;} ll readint(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,k,q; int d[75][75],dp[75][75][75],res[75][75]; int main(){ n=readint(); m=readint(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=1e9; for(int i=1;i<=m;i++){ int u=readint(),v=readint(),w=readint(); chkmin(d[u][v],w); } k=readint(); q=readint(); for(int t=0;t<=min(n,k);t++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dp[t][i][j]=1e9; } } } for(int i=1;i<=n;i++) dp[0][i][i]=0; for(int t=1;t<=min(k,n);t++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int r=1;r<=n;r++){ chkmin(dp[t][i][r],dp[t-1][i][j]+d[j][r]); } } } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ res[i][j]=1e9; for(int t=0;t<=min(n,k);t++){ chkmin(res[i][j],dp[t][i][j]); } } } while(q--){ int x=readint(),y=readint(); if(res[x][y]==1e9) printf("-1\n"); else printf("%d\n",res[x][y]); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...