Submission #989335

#TimeUsernameProblemLanguageResultExecution timeMemory
989335eysbutnoCommuter Pass (JOI18_commuter_pass)C++11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = array<int, 2>;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

template<class T> bool smax(T &a, T b) {
    return a < b ? a = b, 1 : 0;
}
template<class T> bool smin(T &a, T b) {
    return a > b ? a = b, 1 : 0;
}
constexpr ll INF = 1e18;
void solve() {
    int n, m;
    cin >> n >> m;
    pii a, b;
    cin >> a[0] >> a[1] >> b[0] >> b[1];
    --a[0], --a[1], --b[0], --b[1];
    vector<vector<pii>> adj(n);
    for (int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        adj[--u].push_back({--v, w});
        adj[v].push_back({u, w});
    }
    using pll = array<ll, 2>;
    vector<vector<int>> alt(n);
    priority_queue<pll, vector<pll>, greater<>> pq;
    {
        vector<ll> tdist(n, INF);
        pq.push({tdist[a[0]] = 0, a[0]});
        while (!pq.empty()) {
            auto [t, u] = pq.top(); pq.pop();
            if (tdist[u] != t) continue;
            for (auto [v, w] : adj[u]) {
                if (smin(tdist[v], t + w)) {
                    alt[v] = {(int) u};
                    pq.push({tdist[v], v});
                } else if (tdist[v] == t + w) {
                    alt[v].push_back((int) u);
                }
            }
        }
    }
    vector dist(2, vector(n, INF));
    for (int id = 0; id < 2; id++) {
        pq.push({dist[id][b[id]] = 0, b[id]});
        while (!pq.empty()) {
            auto [t, u] = pq.top(); pq.pop();
            if (t != dist[id][u]) continue;
            for (auto [v, w] : adj[u]) {
                if (smin(dist[id][v], t + w)) {
                    pq.push({t + w, v});
                }
            }
        }
    }
    ll res = dist[0][b[1]];
    vector<pll> dp(n, {INF, INF});
    int cnt = 0;
    auto dfs = [&](int u, auto &&self) -> void {
        dp[u] = {dist[0][u], dist[1][u]};
        for (int v : alt[u]) {
            self(v, self);
            for (int id = 0; id < 2; id++) {
                smin(dp[u][id], dp[v][id]);
            }
        }
        for (int id = 0; id < 2; id++) {
            smin(res, dist[id][u] + dp[u][!id]);
        }
        ++cnt; if (cnt > (int) 1e6) assert(false);
    };
    dfs(a[1], dfs);
    cout << res << "\n";
}
int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1; // cin >> t;
    while (t--) solve();
}
/**
 * Construct an alternate graph with all the 
 * edges in possible shortest paths from S to T.
 * Any path from U to V can take any "vertical" path
 * on this alternate graph (b/c it's a DAG). So,
 * consider this alternate graph and DP on the DAG.
*/

Compilation message (stderr)

commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:30:45: error: wrong number of template arguments (0, should be 1)
   30 |     priority_queue<pll, vector<pll>, greater<>> pq;
      |                                             ^
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from commuter_pass.cpp:1:
/usr/include/c++/10/bits/stl_function.h:371:12: note: provided for 'template<class _Tp> struct std::greater'
  371 |     struct greater : public binary_function<_Tp, _Tp, bool>
      |            ^~~~~~~
commuter_pass.cpp:30:46: error: template argument 3 is invalid
   30 |     priority_queue<pll, vector<pll>, greater<>> pq;
      |                                              ^~
commuter_pass.cpp:33:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   33 |         pq.push({tdist[a[0]] = 0, a[0]});
      |            ^~~~
commuter_pass.cpp:34:20: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   34 |         while (!pq.empty()) {
      |                    ^~~~~
commuter_pass.cpp:35:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |             auto [t, u] = pq.top(); pq.pop();
      |                  ^
commuter_pass.cpp:35:30: error: request for member 'top' in 'pq', which is of non-class type 'int'
   35 |             auto [t, u] = pq.top(); pq.pop();
      |                              ^~~
commuter_pass.cpp:35:40: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   35 |             auto [t, u] = pq.top(); pq.pop();
      |                                        ^~~
commuter_pass.cpp:37:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |             for (auto [v, w] : adj[u]) {
      |                       ^
commuter_pass.cpp:40:24: error: request for member 'push' in 'pq', which is of non-class type 'int'
   40 |                     pq.push({tdist[v], v});
      |                        ^~~~
commuter_pass.cpp:47:12: error: missing template arguments before 'dist'
   47 |     vector dist(2, vector(n, INF));
      |            ^~~~
commuter_pass.cpp:49:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   49 |         pq.push({dist[id][b[id]] = 0, b[id]});
      |            ^~~~
commuter_pass.cpp:49:18: error: 'dist' was not declared in this scope
   49 |         pq.push({dist[id][b[id]] = 0, b[id]});
      |                  ^~~~
commuter_pass.cpp:50:20: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   50 |         while (!pq.empty()) {
      |                    ^~~~~
commuter_pass.cpp:51:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |             auto [t, u] = pq.top(); pq.pop();
      |                  ^
commuter_pass.cpp:51:30: error: request for member 'top' in 'pq', which is of non-class type 'int'
   51 |             auto [t, u] = pq.top(); pq.pop();
      |                              ^~~
commuter_pass.cpp:51:40: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   51 |             auto [t, u] = pq.top(); pq.pop();
      |                                        ^~~
commuter_pass.cpp:53:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |             for (auto [v, w] : adj[u]) {
      |                       ^
commuter_pass.cpp:55:24: error: request for member 'push' in 'pq', which is of non-class type 'int'
   55 |                     pq.push({t + w, v});
      |                        ^~~~
commuter_pass.cpp:60:14: error: 'dist' was not declared in this scope
   60 |     ll res = dist[0][b[1]];
      |              ^~~~
commuter_pass.cpp:63:27: error: use of 'auto' in lambda parameter declaration only available with '-std=c++14' or '-std=gnu++14'
   63 |     auto dfs = [&](int u, auto &&self) -> void {
      |                           ^~~~
commuter_pass.cpp: In lambda function:
commuter_pass.cpp:64:40: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<long long int, 2> >, std::array<long long int, 2> >::value_type' {aka 'std::array<long long int, 2>'} and '<brace-enclosed initializer list>')
   64 |         dp[u] = {dist[0][u], dist[1][u]};
      |                                        ^
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from commuter_pass.cpp:1:
/usr/include/c++/10/array:94:12: note: candidate: 'std::array<long long int, 2>& std::array<long long int, 2>::operator=(const std::array<long long int, 2>&)'
   94 |     struct array
      |            ^~~~~
/usr/include/c++/10/array:94:12: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::array<long long int, 2>&'
/usr/include/c++/10/array:94:12: note: candidate: 'std::array<long long int, 2>& std::array<long long int, 2>::operator=(std::array<long long int, 2>&&)'
/usr/include/c++/10/array:94:12: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::array<long long int, 2>&&'
commuter_pass.cpp:66:25: error: expression cannot be used as a function
   66 |             self(v, self);
      |                         ^
commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:76:18: error: no match for call to '(solve()::<lambda(int, int&&)>) (std::array<int, 2>::value_type&, solve()::<lambda(int, int&&)>&)'
   76 |     dfs(a[1], dfs);
      |                  ^
commuter_pass.cpp:63:16: note: candidate: 'solve()::<lambda(int, int&&)>'
   63 |     auto dfs = [&](int u, auto &&self) -> void {
      |                ^
commuter_pass.cpp:63:16: note:   no known conversion for argument 2 from 'solve()::<lambda(int, int&&)>' to 'int&&'