Submission #696620

#TimeUsernameProblemLanguageResultExecution timeMemory
696620anhduc2701Autobus (COCI22_autobus)C++17
70 / 70
123 ms4136 KiB
/* #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") */ #include<bits/stdc++.h> #define int long long using namespace std; #define all(x) x.begin(), x.end() #define len(x) ll(x.size()) #define eb emplace_back #define PI 3.14159265359 #define fi first #define se second #define mp make_pair #define pb push_back #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define BIT(x,i) (1&((x)>>(i))) #define MASK(x) (1LL<<(x)) #define task "tnc" typedef long long ll; const ll INF=1e18; const int maxn=1e6+5; const int mod=1e9+7; const int mo=998244353; using pi=pair<ll,ll>; using vi=vector<ll>; using pii=pair<pair<ll,ll>,ll>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n,m; int f[71][71][71]; int dis[71][71]; signed main() { cin.tie(0),cout.tie(0)->sync_with_stdio(0); //freopen(task".inp" , "r" , stdin); //freopen(task".out" , "w" , stdout); cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dis[i][j]=INF; } } for(int i=1;i<=m;i++){ int a,b,t; cin>>a>>b>>t; dis[a][b]=min(dis[a][b],t); } int k,q; cin>>k>>q; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(i==j)f[i][j][0]=0; else f[i][j][0]=INF; } } for(int i=1;i<=min(n,k);i++){ for(int j=1;j<=n;j++){ for(int z=1;z<=n;z++){ f[j][z][i]=f[j][z][i-1]; } } for(int j=1;j<=n;j++){ for(int z=1;z<=n;z++){ for(int k=1;k<=n;k++){ f[j][k][i]=min(f[j][z][i-1]+dis[z][k],f[j][k][i]); } } } } while(q--){ int c,d; cin>>c>>d; if(f[c][d][min(n,k)]==INF){ cout<<-1<<"\n"; } else{ cout<<f[c][d][min(n,k)]<<"\n"; } } 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...