제출 #772808

#제출 시각아이디문제언어결과실행 시간메모리
772808RecursiveCoCommuter Pass (JOI18_commuter_pass)C++14
0 / 100
265 ms31080 KiB
// CF template, version 3.0 #include <bits/stdc++.h> using namespace std; #define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0) #define getTest int t; cin >> t #define eachTest for (int _var=0;_var<t;_var++) #define get(name) int (name); cin >> (name) #define out(o) cout << (o) #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); } #define sortl(name) sort((name).begin(), (name).end()) #define rev(name) reverse((name).begin(), (name).end()) #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++) #define decision(b) if (b){out("YES");}else{out("NO");} #define int long long int vector<vector<pair<int, int>>> adjList; vector<vector<pair<int, int>>> spgraph; vector<bool> sorted; vector<int> toposort; int n; vector<int> dijkstra(int v) { vector<bool> visited(n, false); vector<int> shortest(n, 1e18); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, v}); while (!pq.empty()) { auto top = pq.top(); pq.pop(); if (visited[top.second]) continue; visited[top.second] = true; shortest[top.second] = min(shortest[top.second], top.first); for (auto con: adjList[top.second]) { if (!visited[con.first]) pq.push({shortest[top.second] + con.second, con.first}); } } return shortest; } void dfs(int v) { sorted[v] = true; for (auto con: spgraph[v]) { if (!sorted[con.first]) dfs(con.first); } toposort.push_back(v); } signed main() { improvePerformance; cin >> n; get(m); get(s); get(t); get(u); get(v); s--; t--; u--; v--; adjList.resize(n); vector<array<int, 3>> edges; forto(m, i) { get(a); get(b); get(w); a--; b--; adjList[a].push_back({b, w}); adjList[b].push_back({a, w}); edges.push_back({a, b, w}); } vector<int> ds = dijkstra(s); vector<int> dt = dijkstra(t); vector<int> du = dijkstra(u); vector<int> dv = dijkstra(v); int dst = ds[t]; spgraph.resize(n); vector<bool> ingraph(n, false); for (auto edge: edges) { int first = edge[0]; int second = edge[1]; int w = edge[2]; if (ds[first] + w + dt[second] == dst) spgraph[first].push_back({second, w}); else if (ds[second] + w + dt[first] == dst) spgraph[second].push_back({first, w}); } forto(n, i) if (spgraph[i].size() || i == t) ingraph[i] = true; sorted.resize(n, false); forto(n, i) { if (ingraph[i] && !sorted[i]) dfs(i); } rev(toposort); vector<vector<pair<int, int>>> invsp(n); forto(n, i) { for (auto con: spgraph[i]) invsp[con.first].push_back({i, con.second}); } vector<int> minu(n, 1e18); vector<int> minv(n, 1e18); vector<int> uxyv(n, 1e18); vector<int> uyxv(n, 1e18); forto(n, i) { int preu = 1e18; int prev = 1e18; for (auto con: invsp[i]) { preu = min(preu, minu[con.first]); prev = min(prev, minv[con.first]); } minu[i] = min(preu, du[i]); minv[i] = min(prev, dv[i]); uxyv[i] = minu[i] + dv[i]; uyxv[i] = du[i] + minv[i]; } out(min(*min_element(uxyv.begin(), uxyv.end()), *min_element(uyxv.begin(), uyxv.end()))); }

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 'm' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:55:5: note: in expansion of macro 'get'
   55 |     get(m);
      |     ^~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 's' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:56:5: note: in expansion of macro 'get'
   56 |     get(s);
      |     ^~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 't' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:57:5: note: in expansion of macro 'get'
   57 |     get(t);
      |     ^~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 'u' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:58:5: note: in expansion of macro 'get'
   58 |     get(u);
      |     ^~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:59:5: note: in expansion of macro 'get'
   59 |     get(v);
      |     ^~~
commuter_pass.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
commuter_pass.cpp:66:5: note: in expansion of macro 'forto'
   66 |     forto(m, i) {
      |     ^~~~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:67:9: note: in expansion of macro 'get'
   67 |         get(a);
      |         ^~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 'b' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:68:9: note: in expansion of macro 'get'
   68 |         get(b);
      |         ^~~
commuter_pass.cpp:10:23: warning: unnecessary parentheses in declaration of 'w' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
commuter_pass.cpp:69:9: note: in expansion of macro 'get'
   69 |         get(w);
      |         ^~~
commuter_pass.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
commuter_pass.cpp:92:5: note: in expansion of macro 'forto'
   92 |     forto(n, i) if (spgraph[i].size() || i == t) ingraph[i] = true;
      |     ^~~~~
commuter_pass.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
commuter_pass.cpp:95:5: note: in expansion of macro 'forto'
   95 |     forto(n, i) {
      |     ^~~~~
commuter_pass.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
commuter_pass.cpp:100:5: note: in expansion of macro 'forto'
  100 |     forto(n, i) {
      |     ^~~~~
commuter_pass.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
commuter_pass.cpp:108:5: note: in expansion of macro 'forto'
  108 |     forto(n, 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...