제출 #857422

#제출 시각아이디문제언어결과실행 시간메모리
857422asdasdqwerCommuter Pass (JOI18_commuter_pass)C++14
15 / 100
2093 ms262144 KiB
// #define FMT_HEADER_ONLY // #include <fmt/ranges.h> #include <bits/stdc++.h> using namespace std; #define int int64_t #define pii pair<int, int> vector<int> dijkstra(int source, vector<vector<pii>> &g) { int n = g.size(); vector<int> dis(n, 1e16); dis[source] = 0; priority_queue<pii> pq; for (int i=0;i<n;i++) { pq.push({-dis[i], i}); } vector<bool> vis(n, false); while (!pq.empty()) { pii t = pq.top();pq.pop(); int node = t.second; if (vis[node]) continue; vis[node] = true; for (pii &x:g[node]) { if (dis[node] + x.second < dis[x.first]) { dis[x.first] = dis[node] + x.second; pq.push({-dis[x.first], x.first}); } } } return dis; } void dfs(int node, vector<int> &vis, vector<int> &topo, vector<vector<int>> &g) { vis[node] = 1; for (int x:g[node]) { if (vis[x] == 0) { dfs(x, vis, topo, g); } } vis[node] = 2; topo.push_back(node); } signed main() { int n, m;cin>>n>>m; int s, t;cin>>s>>t;s--;t--; int u, v;cin>>u>>v;u--;v--; vector<vector<pii>> g(n); for (int i=0;i<m;i++) { int a, b, c;cin>>a>>b>>c; a--;b--; g[a].push_back({b, c}); g[b].push_back({a, c}); } vector<int> disFromS = dijkstra(s, g); vector<vector<int>> dag(n); queue<int> q; q.push(t); while (!q.empty()) { int tp = q.front();q.pop(); for (pii &x:g[tp]) { if (disFromS[tp] == disFromS[x.first] + x.second) { dag[x.first].push_back(tp); q.push(x.first); } } } vector<int> vis(n, 0), topo; for (int i=0;i<n;i++) { if (vis[i] == 0 && dag[i].size()) { dfs(i, vis, topo, dag); } } reverse(topo.begin(), topo.end()); vector<int> disToU = dijkstra(u, g), disToV = dijkstra(v, g); int mn = disToV[u]; vector<int> minGet(n, 1e16); for (int i=0;i<topo.size();i++) { int elem = topo[i]; if (i == 0) { minGet[elem] = disToU[elem]; mn = min(mn, minGet[elem] + disToV[elem]); } for (int x:dag[elem]) { minGet[x] = min(minGet[x], min(minGet[elem], disToU[x])); mn = min(mn, minGet[x] + disToV[x]); } } vector<vector<int>> rev(n); for (int i=0;i<n;i++) { for (int x:dag[i]) { rev[x].push_back(i); } } reverse(topo.begin(), topo.end()); minGet = vector<int>(n, 1e16); for (int i=0;i<topo.size();i++) { int elem = topo[i]; if (i == 0) { minGet[elem] = disToU[elem]; mn = min(mn, minGet[elem] + disToV[elem]); } for (int x:rev[elem]) { minGet[x] = min(minGet[x], min(minGet[elem], disToU[x])); mn = min(mn, minGet[x] + disToV[x]); } } cout << mn << "\n"; }

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:95:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for (int i=0;i<topo.size();i++) {
      |                  ~^~~~~~~~~~~~
commuter_pass.cpp:119:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |     for (int i=0;i<topo.size();i++) {
      |                  ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...