제출 #858866

#제출 시각아이디문제언어결과실행 시간메모리
858866themaver1cksCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
356 ms21604 KiB
/** 。∠(*・ω・)っ ⌒ 由 ~ (( ,,・з・,, )) _Π_____。 /______/~\ | 田田|門| **/ #include <bits/stdc++.h> using namespace std; #define fori(i, l, r) for(int (i) = (l); i < (r); ++i) #define forie(i, l, r) for (int (i) = (l); i <= (r); ++i) #define ford(i, l, r) for (int (i) = (l); i > (r); --i) #define forde(i, l, r) for (int (i) = (l); i >= (r); --i) #define int long long #define i_inf INT_MAX #define inf LLONG_MAX #define ii pair<int,int> #define fi first #define se second #define gcd __gcd #define lcm(x,y) x * y/ gcd(x,y) #define pb push_back #define sz size #define all(x) begin(x), end(x) #define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr); #define el "\n" #define sp " " // int dr[] = {-1, 0, 1, 0}; int dc[] = {0, 1, 0, -1}; // var declare const int maxn = 2e5 + 3; int n, m, S, T, U, V; // ds declare vector <ii> adj[maxn]; // vector <int> dijkstra(int s) { vector <int> dist(n+3, inf); priority_queue<ii, vector<ii>, greater<ii>> pq; dist[s] = 0; pq.push({0, s}); while (pq.sz()) { auto [d, u] = pq.top(); pq.pop(); if (d > dist[u]) continue; for (auto [v, w]: adj[u]) { if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; pq.push({dist[v], v}); } } } return dist; } // int commuter_pass(int S, int T) { auto fromS = dijkstra(S); auto fromT = dijkstra(T); auto fromU = dijkstra(U); auto fromV = dijkstra(V); vector <int> f(n+1, inf); vector <int> order(n+1); iota(order.begin()+1, order.end(), 1); sort(order.begin()+1, order.end(), [&](int x, int y){ return fromS[x] < fromS[y]; }); int ans = fromU[V]; forie(u, 1, n) { f[u] = min(f[u], fromU[u]); for (auto [v, w]: adj[u]) { if (fromS[u] + w == fromS[v] && fromS[u] + w + fromT[v] == fromS[T]) { f[v] = min(f[v], f[u]); } } if (fromS[u] + fromT[u] == fromS[T]) ans = min(ans, f[u] + fromV[u]); } return ans; } // void solve() { cin >> n >> m; cin >> S >> T >> U >> V; forie(i, 1, m) { int u, v, w; cin >> u >> v >> w; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } cout << min(commuter_pass(S, T), commuter_pass(T, S)); } // void multi_test() { int t; cin >> t; while (t--) solve(); } // int32_t main() { fastio; solve(); return 0; } /** **/

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

commuter_pass.cpp: In function 'long long int commuter_pass(long long int, long long int)':
commuter_pass.cpp:13:33: warning: unnecessary parentheses in declaration of 'u' [-Wparentheses]
   13 | #define forie(i, l, r) for (int (i) = (l); i <= (r); ++i)
      |                                 ^
commuter_pass.cpp:75:5: note: in expansion of macro 'forie'
   75 |     forie(u, 1, n)
      |     ^~~~~
commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:13:33: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   13 | #define forie(i, l, r) for (int (i) = (l); i <= (r); ++i)
      |                                 ^
commuter_pass.cpp:95:2: note: in expansion of macro 'forie'
   95 |  forie(i, 1, m)
      |  ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...