제출 #683528

#제출 시각아이디문제언어결과실행 시간메모리
683528yogesh_saneCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
2070 ms19416 KiB
#include <iostream> #include <vector> #include <queue> #include <stack> #include <climits> using namespace std; int n, m, s, t, u, v; vector<vector<int>> parents; vector<vector<pair<int, int>>> adj; vector<bool> visited; vector<long long> distU, distV; vector<int> sp; long long ans = LONG_LONG_MAX; void find_ans(){ vector<bool> on_sp(n+1); for(int j = 0; j < sp.size(); j++) on_sp[sp[j]] = true; long long minu = LONG_LONG_MAX/2, minv = LONG_LONG_MAX/2; for(int k = 1; k <= n; k++) if(on_sp[k]) minu = min(minu, distU[k]); for(int k = 1; k <= n; k++) if(on_sp[k]) minv = min(minv, distV[k]); ans = min(ans, minu+minv); } void dfs(int node){ sp.push_back(node); if(node == s){ find_ans(); } for(auto gp : parents[node]) dfs(gp); sp.pop_back(); } void dijkstras_ST(){ priority_queue<pair<long long, int>> q; vector<long long>dist(n+1,LONG_LONG_MAX); 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); } } } } void dijkstras_UV(int start, vector<long long> &dist){ priority_queue<pair<long long, int>> q; q.push({0,start}); dist[start] = 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; q.push({-dist[next],next}); } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("in.txt","r",stdin); cin >> n >> m >> s >> t >> u >> v; adj = vector<vector<pair<int, int>>>(n+1); parents = vector<vector<int>>(n+1); visited = vector<bool>(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}); } dijkstras_ST(); fill(visited.begin(), visited.end(),false); fill(visited.begin(), visited.end(), false); distU = vector<long long>(n+1, LONG_LONG_MAX); dijkstras_UV(u, distU); fill(visited.begin(), visited.end(), false); distV = vector<long long>(n+1, LONG_LONG_MAX); dijkstras_UV(v, distV); dfs(t); ans = min(ans,distU[v]); cout << ans << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'void find_ans()':
commuter_pass.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int j = 0; j < sp.size(); j++)
      |                    ~~^~~~~~~~~~~
commuter_pass.cpp: In function 'void dijkstras_ST()':
commuter_pass.cpp:46:19: warning: unused variable 'dist_node' [-Wunused-variable]
   46 |         long long dist_node = -q.top().first;
      |                   ^~~~~~~~~
commuter_pass.cpp: In function 'void dijkstras_UV(int, std::vector<long long int>&)':
commuter_pass.cpp:71:19: warning: unused variable 'dist_node' [-Wunused-variable]
   71 |         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...