結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー | みここ |
提出日時 | 2022-12-12 04:13:39 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,635 bytes |
コンパイル時間 | 1,047 ms |
コンパイル使用メモリ | 78,856 KB |
実行使用メモリ | 32,148 KB |
最終ジャッジ日時 | 2024-11-06 04:20:16 |
合計ジャッジ時間 | 19,304 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 RE * 23 |
ソースコード
#include <iostream>#include <cassert>#include <vector>using namespace std;typedef long long ll;template <typename T = int>struct edge{int from, to;T cost;int id;operator int() const{return to;}};template <typename T = int>struct graph{int n, m;std::vector<std::vector<edge<T>>> g;graph() {}graph(int n) : n(n), m(0){g.resize(n);}void add_directed_edge(int from, int to, T cost = 1){assert(0 <= from && from < n);assert(0 <= to && to < n);g[from].push_back((edge<T>){from, to, cost, m++});}void add_undirected_edge(int from, int to, T cost = 1){assert(0 <= from && from < n);assert(0 <= to && to < n);g[from].push_back((edge<T>){from, to, cost, m});g[to].push_back((edge<T>){to, from, cost, m++});}int size(){return n;}int edge_size(){return m;}inline const std::vector<edge<T>> &operator[](const int &u) const{return g[u];}inline std::vector<edge<T>> &operator[](const int &u){return g[u];}};int main(){int n, m;cin >> n >> m;ll h[100005];for (int u = 0; u < n; u++){cin >> h[u];}graph<ll> g(n * 2), r(n * 2);for (int u = 0; u < n; u++){g.add_directed_edge(u * 2, u * 2 + 1, 0);r.add_directed_edge(u * 2 + 1, u * 2, 0);}for (int i = 0; i < m; i++){int x, y;cin >> x >> y;x--;y--;if (x > y){swap(x, y);}if (h[x] < h[y]){g.add_directed_edge(x * 2, y * 2 + 1, h[y] - h[x]);r.add_directed_edge(y * 2, x * 2 + 1, 0);}else{g.add_directed_edge(x * 2 + 1, y * 2, 0);r.add_directed_edge(y * 2 + 1, x * 2, h[x] - h[y]);}}ll d0[100005], d1[100005];for (int u = 0; u < n * 2; u++){d0[u] = d1[u] = -1;}d0[0] = 0;for (int u = 0; u < n * 2; u++){if (d0[u] == -1){continue;}for (edge<ll> e : g[u]){d0[e.to] = max(d0[e.to], d0[u] + e.cost);}}cout << d0[n * 2 - 1] << endl;d1[n * 2 - 1] = 0;for (int u = n * 2 - 1; u >= 0; u--){if (d1[u] == -1){continue;}for (edge<ll> e : r[u]){d1[e.to] = max(d1[e.to], d1[u] + e.cost);}}cout << d1[0] << endl;}