답안 #257017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257017 2020-08-03T14:01:48 Z Bruteforceman Aesthetic (NOI20_aesthetic) C++11
38 / 100
1803 ms 84300 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int logn = 19;
const long long inf = 1e16;
int anc[logn + 1][maxn];
int l[maxn], r[maxn], w[maxn];
vector <int> g[maxn], t[maxn];
long long ans[maxn];
int dep[maxn];
int n, m;

struct data {
  long long dist;
  int node;
  data (long long dist, int node) : dist(dist), node(node) {}
  data () {}
  bool operator < (data d) const {
    return dist > d.dist;
  }
};

vector <long long> dijstra(int root) {
  priority_queue <data> Q;

  vector <long long> dist (n, inf);
  Q.emplace(0, root);
  dist[root] = 0;
  while(!Q.empty()) {
    int node = Q.top().node;
    long long var = Q.top().dist;
    Q.pop();
    if(var != dist[node]) continue;
    for(int e : g[node]) {
      int x = l[e] ^ r[e] ^ node;
      if(w[e] + dist[node] < dist[x]) {
        dist[x] = w[e] + dist[node];
        Q.emplace(dist[x], x);
      }
    }
  }
  return dist;
}
void dfs(int x) {
  for(int i = 1; i <= logn; i++) {
    anc[i][x] = anc[i - 1][anc[i - 1][x]];
  }
  for(int i : t[x]) {
    dep[i] = 1 + dep[x];
    anc[0][i] = x;
    dfs(i);
  }
}
int lca(int x, int y) {
  if(dep[x] > dep[y]) swap(x, y);
  for(int i = logn; i >= 0; i--) {
    if(dep[y] - (1 << i) >= dep[x]) {
      y = anc[i][y];
    }
  }
  if(x == y) return x;
  for(int i = logn; i >= 0; i--) {
    if(anc[i][x] != anc[i][y]) {
      x = anc[i][x];
      y = anc[i][y];
    }
  }
  return anc[0][x];
}
int main() {
  scanf("%d %d", &n, &m);
  for(int i = 0; i < m; i++) {
    scanf("%d %d %d", &l[i], &r[i], &w[i]);
    l[i] -= 1;
    r[i] -= 1;
    g[l[i]].push_back(i);
    g[r[i]].push_back(i);
  }
  vector <long long> forward = dijstra(0);
  vector <int> par (n);
  for(int i = 1; i < n; i++) {
    for(int e : g[i]) {
      int x = l[e] ^ r[e] ^ i;
      if(forward[x] + w[e] == forward[i]) {
        par[i] = e;
        t[x].push_back(i);
        break;
      }
    }
  }
  dfs(0);
  vector <long long> backward = dijstra(n - 1);
  int cur = n - 1;
  vector <bool> onPath (m);
  vector <int> id (n);
  while(cur != 0) {
    int e = par[cur];
    onPath[e] = true;
    cur = anc[0][cur];
    id[dep[cur]] = e;
  }
  for(int i = 0; i < m; i++) ans[i] = inf;
  vector <vector <pair <int, int>>> cont (n); 
  for(int i = 0; i < m; i++) {
    if(onPath[i]) continue;
    ans[i] = forward[n - 1];
    int p = lca(l[i], n - 1);
    int q = lca(r[i], n - 1);
    if(dep[p] > dep[q])  {
      swap(p, q);
      swap(l[i], r[i]);
    }
    long long cost = w[i] + forward[l[i]] + backward[r[i]];
    cont[dep[p]].emplace_back(cost, 1);
    cont[dep[q]].emplace_back(cost, -1);
  }
  multiset <long long> bst;
  for(int i = 0; i < dep[n - 1]; i++) {
    for(auto j : cont[i]) {
      if(j.second == 1) bst.insert(j.first);
      else bst.erase(bst.find(j.first));
    }
    ans[id[i]] = bst.empty() ? inf : *bst.begin();
  }
  int mx = w[m - 1];
  long long res = 0;
  for(int i = m - 2; i >= 0; i--) {
    long long p = forward[l[i]] + mx + w[i] + backward[r[i]];
    long long q = forward[r[i]] + mx + w[i] + backward[l[i]];
    res = max(res, min({ans[i], p, q}));
    mx = max(mx, w[i]);
  }
  printf("%lld\n", res);
  return 0;
}

Compilation message

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
   ~~~~~^~~~~~~~~~~~~~~~~
Aesthetic.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &l[i], &r[i], &w[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 14592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 14592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1658 ms 80012 KB Output is correct
2 Correct 1508 ms 80008 KB Output is correct
3 Correct 1455 ms 79592 KB Output is correct
4 Correct 1803 ms 80616 KB Output is correct
5 Correct 1352 ms 79656 KB Output is correct
6 Correct 1396 ms 81928 KB Output is correct
7 Correct 1521 ms 82728 KB Output is correct
8 Correct 1395 ms 81440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1699 ms 80996 KB Output is correct
2 Correct 1348 ms 80112 KB Output is correct
3 Correct 1154 ms 79456 KB Output is correct
4 Correct 1289 ms 84300 KB Output is correct
5 Correct 1346 ms 81016 KB Output is correct
6 Correct 1206 ms 83300 KB Output is correct
7 Correct 1496 ms 81332 KB Output is correct
8 Correct 1607 ms 80536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1008 ms 64604 KB Output is correct
2 Correct 442 ms 75072 KB Output is correct
3 Correct 671 ms 49712 KB Output is correct
4 Correct 523 ms 49804 KB Output is correct
5 Correct 541 ms 49764 KB Output is correct
6 Correct 587 ms 49792 KB Output is correct
7 Correct 537 ms 49888 KB Output is correct
8 Correct 512 ms 49920 KB Output is correct
9 Correct 524 ms 49816 KB Output is correct
10 Correct 590 ms 49900 KB Output is correct
11 Correct 535 ms 49876 KB Output is correct
12 Correct 1057 ms 65164 KB Output is correct
13 Correct 508 ms 49896 KB Output is correct
14 Correct 291 ms 74080 KB Output is correct
15 Correct 266 ms 69368 KB Output is correct
16 Correct 1045 ms 67108 KB Output is correct
17 Correct 1100 ms 66640 KB Output is correct
18 Correct 972 ms 70504 KB Output is correct
19 Correct 409 ms 79608 KB Output is correct
20 Correct 373 ms 79484 KB Output is correct
21 Correct 376 ms 79736 KB Output is correct
22 Correct 372 ms 79228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1008 ms 64604 KB Output is correct
2 Correct 442 ms 75072 KB Output is correct
3 Correct 671 ms 49712 KB Output is correct
4 Correct 523 ms 49804 KB Output is correct
5 Correct 541 ms 49764 KB Output is correct
6 Correct 587 ms 49792 KB Output is correct
7 Correct 537 ms 49888 KB Output is correct
8 Correct 512 ms 49920 KB Output is correct
9 Correct 524 ms 49816 KB Output is correct
10 Correct 590 ms 49900 KB Output is correct
11 Correct 535 ms 49876 KB Output is correct
12 Correct 1057 ms 65164 KB Output is correct
13 Correct 508 ms 49896 KB Output is correct
14 Correct 291 ms 74080 KB Output is correct
15 Correct 266 ms 69368 KB Output is correct
16 Correct 1045 ms 67108 KB Output is correct
17 Correct 1100 ms 66640 KB Output is correct
18 Correct 972 ms 70504 KB Output is correct
19 Correct 409 ms 79608 KB Output is correct
20 Correct 373 ms 79484 KB Output is correct
21 Correct 376 ms 79736 KB Output is correct
22 Correct 372 ms 79228 KB Output is correct
23 Correct 854 ms 70292 KB Output is correct
24 Correct 319 ms 60436 KB Output is correct
25 Correct 547 ms 51192 KB Output is correct
26 Correct 551 ms 51564 KB Output is correct
27 Correct 556 ms 51332 KB Output is correct
28 Correct 563 ms 47988 KB Output is correct
29 Correct 560 ms 47536 KB Output is correct
30 Correct 626 ms 47984 KB Output is correct
31 Correct 601 ms 48024 KB Output is correct
32 Correct 533 ms 46960 KB Output is correct
33 Correct 613 ms 47868 KB Output is correct
34 Correct 804 ms 64632 KB Output is correct
35 Correct 530 ms 47212 KB Output is correct
36 Correct 258 ms 69680 KB Output is correct
37 Correct 221 ms 49836 KB Output is correct
38 Incorrect 797 ms 65408 KB Output isn't correct
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 14592 KB Output isn't correct
2 Halted 0 ms 0 KB -