# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872665 | HossamHero7 | Autobus (COCI22_autobus) | C++14 | 1087 ms | 756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int edge[75][75];
vector<pair<int,ll>> adj[75];
ll dp[75][75][2];
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) edge[i][j] = 1e9;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
edge[a][b] = min(edge[a][b] , c);
}
int cnt = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) {
if(edge[i][j] != 1e9) adj[i].push_back({j,edge[i][j]}) , cnt++;
}
}
int k,q;
cin>>k>>q;
k = min(k,cnt);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j][0] = (i == j ? 0 : 1e18);
for(int rem=1;rem<=k;rem++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dp[i][j][rem&1] = dp[i][j][rem-1&1];
for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]);
}
}
}
while(q--){
int a,b;
cin>>a>>b;
cout<<(dp[a][b][k&1] == 1e18 ? -1 : dp[a][b][k&1])<<endl;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
# | 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... |