Submission #1082984

# Submission time Handle Problem Language Result Execution time Memory
1082984 2024-09-02T09:35:13 Z avighna Aesthetic (NOI20_aesthetic) C++17
35 / 100
2000 ms 55512 KB
#include <bits/stdc++.h>

typedef long long ll;

struct To {
  ll v, w;
  ll i;
};

struct Edge {
  ll u, v, w;
};

const ll inf = 1e15;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll n, m;
  std::cin >> n >> m;
  std::vector<std::vector<To>> adj(n + 1);
  std::vector<Edge> edges;
  for (ll i = 0, u, v, w; i < m; ++i) {
    std::cin >> u >> v >> w;
    adj[u].push_back({v, w, i});
    adj[v].push_back({u, w, i});
    edges.push_back({u, v, w});
  }

  auto sssp = [&](ll node) {
    std::vector<ll> ans(n + 1, inf);
    std::vector<bool> vis(n + 1);
    std::priority_queue<std::pair<ll, ll>> pq;
    ans[node] = 0;
    pq.push({0, node});
    while (!pq.empty()) {
      auto [d, node] = pq.top();
      d *= -1;
      pq.pop();
      if (vis[node]) {
        continue;
      }
      vis[node] = true;
      for (auto [ch, w, cur_i] : adj[node]) {
        if (ans[ch] > d + w) {
          ans[ch] = d + w;
          pq.push({-ans[ch], ch});
        }
      }
    }
    return ans;
  };

  auto sssp1 = sssp(1);
  auto ssspn = sssp(n);

  std::vector<bool> active_edge(m), is_bridge(m), vis(n + 1), enc(n + 1);
  std::vector<ll> low(n + 1), tin(n + 1);

  auto check = [&](ll x) {
    for (ll i = 0; i < m; ++i) {
      auto [u, v, w] = edges[i];
      active_edge[i] =
          sssp1[u] + w + ssspn[v] <= x or sssp1[v] + w + ssspn[u] <= x;
    }
    vis.assign(n + 1, false);
    enc.assign(n + 1, false);
    enc[n] = true;
    ll timer = 0;
    std::function<void(ll, ll)> dfs;
    dfs = [&](ll node, ll par) {
      if (vis[node]) {
        return;
      }
      vis[node] = true;
      tin[node] = timer++;
      low[node] = tin[node];
      for (auto &[ch, w, i] : adj[node]) {
        if (ch == par or !active_edge[i]) {
          continue;
        }
        if (!vis[ch]) {
          dfs(ch, node);
          enc[node] = enc[node] || enc[ch];
        }
        is_bridge[i] = low[ch] > tin[node] and enc[ch];
        low[node] = std::min(low[node], low[ch]);
      }
    };
    dfs(1, 0);
    ll worst_road = edges[m - 1].w;
    for (ll i = m - 2; i >= 0; --i) {
      auto [u, v, w] = edges[i];
      if (is_bridge[i] and
          std::min(sssp1[u] + ssspn[v], sssp1[v] + ssspn[u]) + w + worst_road >
              x) {
        return true;
      }
      worst_road = std::max(worst_road, edges[i].w);
    }
    return false;
  };

  ll s = sssp1[n], e = 1e15;
  while (s < e) {
    ll m = s + (e - s) / 2;
    if (check(m)) {
      s = m + 1;
    } else {
      e = m;
    }
  }
  std::cout << s << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 864 ms 44008 KB Output is correct
2 Correct 838 ms 44516 KB Output is correct
3 Correct 833 ms 43752 KB Output is correct
4 Correct 902 ms 43928 KB Output is correct
5 Correct 897 ms 44080 KB Output is correct
6 Correct 923 ms 45032 KB Output is correct
7 Correct 907 ms 44776 KB Output is correct
8 Correct 920 ms 45072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 975 ms 45028 KB Output is correct
2 Correct 910 ms 44336 KB Output is correct
3 Correct 798 ms 44388 KB Output is correct
4 Correct 836 ms 45036 KB Output is correct
5 Correct 864 ms 44204 KB Output is correct
6 Correct 818 ms 44384 KB Output is correct
7 Correct 848 ms 44228 KB Output is correct
8 Correct 949 ms 44524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 55512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 55512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 784 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 864 ms 44008 KB Output is correct
18 Correct 838 ms 44516 KB Output is correct
19 Correct 833 ms 43752 KB Output is correct
20 Correct 902 ms 43928 KB Output is correct
21 Correct 897 ms 44080 KB Output is correct
22 Correct 923 ms 45032 KB Output is correct
23 Correct 907 ms 44776 KB Output is correct
24 Correct 920 ms 45072 KB Output is correct
25 Correct 975 ms 45028 KB Output is correct
26 Correct 910 ms 44336 KB Output is correct
27 Correct 798 ms 44388 KB Output is correct
28 Correct 836 ms 45036 KB Output is correct
29 Correct 864 ms 44204 KB Output is correct
30 Correct 818 ms 44384 KB Output is correct
31 Correct 848 ms 44228 KB Output is correct
32 Correct 949 ms 44524 KB Output is correct
33 Execution timed out 2029 ms 55512 KB Time limit exceeded
34 Halted 0 ms 0 KB -