Submission #683493

#TimeUsernameProblemLanguageResultExecution timeMemory
683493yogesh_saneCommuter Pass (JOI18_commuter_pass)C++17
16 / 100
250 ms19264 KiB
#include <iostream> #include <vector> #include <queue> #include <stack> #include <climits> using namespace std; void dfs(int s, vector<vector<int>> &adj, vector<bool> &on_sp, vector<bool> &visited){ if(visited[s]) return; visited[s] = true; on_sp[s] = true; for(auto u : adj[s]) dfs(u,adj,on_sp,visited); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("in.txt","r",stdin); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; vector<vector<pair<int, int>>> adj(n+1); for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } priority_queue<pair<long long, int>> q; vector<long long>dist(n+1,LONG_LONG_MAX); vector<bool> visited(n+1); vector<vector<int>>parents(n+1); vector<bool> on_sp(n+1); q.push({0,s}); dist[s] = 0; while(!q.empty()){ int node = q.top().second; long long dist_node = -q.top().first; q.pop(); if(visited[node]) continue; visited[node] = true; for(auto edge : adj[node]){ int next = edge.first; int weight = edge.second; if(dist[node] + weight < dist[next]){ dist[next] = dist[node] + weight; parents[next].clear(); parents[next].push_back(node); q.push({-dist[next],next}); }else if(dist[node] + weight == dist[next]){ parents[next].push_back(node); } } } fill(visited.begin(), visited.end(), false); dfs(t,parents,on_sp,visited); fill(visited.begin(), visited.end(), false); vector<long long> distV(n+1, LONG_LONG_MAX); q.push({0,v}); distV[v] = 0; while(!q.empty()){ int node = q.top().second; long long dist_node = -q.top().first; q.pop(); if(visited[node]) continue; visited[node] = true; for(auto edge : adj[node]){ int next = edge.first; int weight = edge.second; if(distV[node] + weight < distV[next]){ distV[next] = distV[node] + weight; q.push({-distV[next],next}); } } } long long ans = LONG_LONG_MAX; for(int i = 1; i <= n; i++) if(on_sp[i]) ans = min(ans, distV[i]); cout << ans << '\n'; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:37:19: warning: unused variable 'dist_node' [-Wunused-variable]
   37 |         long long dist_node = -q.top().first;
      |                   ^~~~~~~~~
commuter_pass.cpp:64:19: warning: unused variable 'dist_node' [-Wunused-variable]
   64 |         long long dist_node = -q.top().first;
      |                   ^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...