Submission #703968

#TimeUsernameProblemLanguageResultExecution timeMemory
703968ancuber1031Autobus (COCI22_autobus)C++14
0 / 70
13 ms400 KiB
#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< pii > > g(n+1); vector<vector<int> > edge(n+1,vector<int>(n+1,1e18)); while(m--) { int a, b, t; cin>>a>>b>>t; edge[a][b] = min(t,edge[a][b]); } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (edge[i][j] < 1e18) { g[i].pb({j,edge[i][j]}); } } } int k, q; cin>>k>>q; while(q--) { int c, d; cin>>c>>d; vector<int> dis(n+1,1e18), vis(n+1,0), mn(n+1,1e9+5); dis[c] = 0; p_q < pair<pair<int,int>,int>,vector<pair<pair<int,int>,int> >,greater<pair<pair<int,int>,int> > > pq; pq.push({{0,0},c}); while(!pq.empty()) { pair<pair<int,int>,int> cur = pq.top(); pq.pop(); if (vis[cur.second] || cur.first.second == k) continue; vis[cur.second] = 1; for (auto [v,w] : g[cur.second]) { if (dis[v] > dis[cur.second]+w || (dis[v] == dis[cur.second]+w && cur.first.second+1 < mn[v])) { dis[v] = dis[cur.second]+w; mn[v] = cur.first.second+1; pq.push({{dis[v],mn[v]},v}); } } } if (dis[d] == 1e18) cout<<-1<<endl; else cout<<dis[d]<<endl; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:42:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |             for (auto [v,w] : g[cur.second]) {
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...