Submission #261387

# Submission time Handle Problem Language Result Execution time Memory
261387 2020-08-11T16:57:52 Z Nightlight Aesthetic (NOI20_aesthetic) C++14
100 / 100
999 ms 80896 KB
#include <cstdio>
#include <queue>
#include <cstring>
#define pii pair<long long, int>
using namespace std;
 
int N, M;
vector<pii> adj[300005];
priority_queue<pii, vector<pii>, greater<pii>> pq;
long long dist[2][300005];
int U[300005], V[300005];
bool can[300005], ada[300005];
long long W[300005], best[300005];
vector<pair<int, int>> adj2[300005];
int disc[300005], low[300005], waktu, need;
long long p1[300005], p2[300005], pp1[300005], pp2[300005];
bool ok;
 
void BFS(int id, int st) {
  memset(ada, 0, sizeof(ada));
  pq.emplace(0LL, st);
  dist[id][st] = 0;
  int u, v;
  long long len, w;
  while(!pq.empty()) {
    u = pq.top().second;
    len = pq.top().first;
    pq.pop();
    if(len != dist[id][u]) continue;
    for(pii now : adj[u]) {
      v = now.second;
      w = now.first;
      if(dist[id][v] > len + w) {
        dist[id][v] = len + w;
        pq.emplace(dist[id][v], v);
      }
    }
  }
}
 
void DFS(int u, int p) {
  disc[u] = low[u] = ++waktu;
  int v, id;
  for(pair<int, int> now : adj2[u]) {
    id = now.second;
    if(ada[id] == 0) continue;
    v = now.first; 
    if(disc[v] <= need) {
      DFS(v, u);
      if(low[v] > disc[u] && can[id] && disc[N] >= disc[v] && disc[N] <= waktu) {
        ok = 1;
      }else low[u] = min(low[u], low[v]);
    }else if(p != v) {
      low[u] = min(low[u], disc[v]);
    }
  }
}
 
bool check(long long now) {
  ok = 0;
  need = waktu;
  for(int i = 1; i <= M; i++) {
    if(p1[i] > now && p2[i] > now) ada[i] = 0;
    else ada[i] = 1;
    if(pp1[i] > now && pp2[i] > now) can[i] = 1;
    else can[i] = 0;
  }
  DFS(1, 0);
  if(disc[N] <= need) return 1;
  if(ok) return 1;
  return 0;
}
 
int main() {
  memset(dist, 0x3f3f3f3f, sizeof(dist));
  scanf("%d %d", &N, &M);
  int u, v;
  long long w;
  for(int i = 1; i <= M; i++) {
    scanf("%d %d %lld", &u, &v, &w);
    U[i] = u, V[i] = v, W[i] = w;
    adj[u].emplace_back(w, v);
    adj[v].emplace_back(w, u);
    adj2[u].emplace_back(v, i);
    adj2[v].emplace_back(u, i);
  }
  for(int i = M - 1; i > 0; i--) {
    best[i] = max(best[i + 1], W[i + 1]);
  }
  BFS(0, 1);
  BFS(1, N);
  for(int i = 1; i <= M; i++) {
    p1[i] = dist[0][U[i]] + W[i] + dist[1][V[i]];
    p2[i] = dist[0][V[i]] + W[i] + dist[1][U[i]];
    pp1[i] = dist[0][U[i]] + best[i] + W[i] + dist[1][V[i]];
    pp2[i] = dist[0][V[i]] + best[i] + W[i] + dist[1][U[i]];
  }
  long long l = dist[0][N], r = dist[0][N] + best[1], res = dist[0][N], mid;
  while(l <= r) {
    mid = (l + r) >> 1;
    if(check(mid)) {
      l = mid + 1;
      res = l;
    }else r = mid - 1;
  }
  printf("%lld\n", res);
}

Compilation message

Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:76: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:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %lld", &u, &v, &w);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19456 KB Output is correct
2 Correct 14 ms 19456 KB Output is correct
3 Correct 15 ms 19456 KB Output is correct
4 Correct 14 ms 19456 KB Output is correct
5 Correct 14 ms 19456 KB Output is correct
6 Correct 14 ms 19456 KB Output is correct
7 Correct 16 ms 19456 KB Output is correct
8 Correct 14 ms 19456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19456 KB Output is correct
2 Correct 14 ms 19456 KB Output is correct
3 Correct 15 ms 19456 KB Output is correct
4 Correct 14 ms 19456 KB Output is correct
5 Correct 14 ms 19456 KB Output is correct
6 Correct 14 ms 19456 KB Output is correct
7 Correct 16 ms 19456 KB Output is correct
8 Correct 14 ms 19456 KB Output is correct
9 Correct 16 ms 19840 KB Output is correct
10 Correct 16 ms 19712 KB Output is correct
11 Correct 16 ms 19712 KB Output is correct
12 Correct 16 ms 19712 KB Output is correct
13 Correct 16 ms 19840 KB Output is correct
14 Correct 17 ms 19840 KB Output is correct
15 Correct 16 ms 19840 KB Output is correct
16 Correct 16 ms 19840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 900 ms 65400 KB Output is correct
2 Correct 848 ms 65400 KB Output is correct
3 Correct 860 ms 65016 KB Output is correct
4 Correct 886 ms 65016 KB Output is correct
5 Correct 983 ms 65144 KB Output is correct
6 Correct 956 ms 66424 KB Output is correct
7 Correct 966 ms 65960 KB Output is correct
8 Correct 889 ms 66424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 999 ms 66296 KB Output is correct
2 Correct 943 ms 65612 KB Output is correct
3 Correct 907 ms 64888 KB Output is correct
4 Correct 857 ms 64908 KB Output is correct
5 Correct 892 ms 65272 KB Output is correct
6 Correct 887 ms 65400 KB Output is correct
7 Correct 908 ms 65660 KB Output is correct
8 Correct 924 ms 65912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 755 ms 63236 KB Output is correct
2 Correct 329 ms 63136 KB Output is correct
3 Correct 514 ms 69624 KB Output is correct
4 Correct 533 ms 69580 KB Output is correct
5 Correct 527 ms 69428 KB Output is correct
6 Correct 504 ms 69752 KB Output is correct
7 Correct 510 ms 69556 KB Output is correct
8 Correct 500 ms 69892 KB Output is correct
9 Correct 513 ms 69496 KB Output is correct
10 Correct 498 ms 70008 KB Output is correct
11 Correct 491 ms 69752 KB Output is correct
12 Correct 713 ms 65468 KB Output is correct
13 Correct 503 ms 69884 KB Output is correct
14 Correct 259 ms 80632 KB Output is correct
15 Correct 250 ms 80632 KB Output is correct
16 Correct 787 ms 66080 KB Output is correct
17 Correct 794 ms 65156 KB Output is correct
18 Correct 830 ms 65312 KB Output is correct
19 Correct 341 ms 63404 KB Output is correct
20 Correct 365 ms 63240 KB Output is correct
21 Correct 368 ms 63352 KB Output is correct
22 Correct 351 ms 63276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 755 ms 63236 KB Output is correct
2 Correct 329 ms 63136 KB Output is correct
3 Correct 514 ms 69624 KB Output is correct
4 Correct 533 ms 69580 KB Output is correct
5 Correct 527 ms 69428 KB Output is correct
6 Correct 504 ms 69752 KB Output is correct
7 Correct 510 ms 69556 KB Output is correct
8 Correct 500 ms 69892 KB Output is correct
9 Correct 513 ms 69496 KB Output is correct
10 Correct 498 ms 70008 KB Output is correct
11 Correct 491 ms 69752 KB Output is correct
12 Correct 713 ms 65468 KB Output is correct
13 Correct 503 ms 69884 KB Output is correct
14 Correct 259 ms 80632 KB Output is correct
15 Correct 250 ms 80632 KB Output is correct
16 Correct 787 ms 66080 KB Output is correct
17 Correct 794 ms 65156 KB Output is correct
18 Correct 830 ms 65312 KB Output is correct
19 Correct 341 ms 63404 KB Output is correct
20 Correct 365 ms 63240 KB Output is correct
21 Correct 368 ms 63352 KB Output is correct
22 Correct 351 ms 63276 KB Output is correct
23 Correct 838 ms 67044 KB Output is correct
24 Correct 407 ms 63336 KB Output is correct
25 Correct 591 ms 65656 KB Output is correct
26 Correct 513 ms 64768 KB Output is correct
27 Correct 535 ms 64936 KB Output is correct
28 Correct 528 ms 65944 KB Output is correct
29 Correct 536 ms 65016 KB Output is correct
30 Correct 526 ms 65316 KB Output is correct
31 Correct 510 ms 65784 KB Output is correct
32 Correct 514 ms 64888 KB Output is correct
33 Correct 511 ms 65912 KB Output is correct
34 Correct 846 ms 66184 KB Output is correct
35 Correct 514 ms 65528 KB Output is correct
36 Correct 259 ms 80896 KB Output is correct
37 Correct 259 ms 80824 KB Output is correct
38 Correct 772 ms 66268 KB Output is correct
39 Correct 752 ms 65636 KB Output is correct
40 Correct 761 ms 67044 KB Output is correct
41 Correct 379 ms 63352 KB Output is correct
42 Correct 382 ms 63480 KB Output is correct
43 Correct 379 ms 63608 KB Output is correct
44 Correct 392 ms 63412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19456 KB Output is correct
2 Correct 14 ms 19456 KB Output is correct
3 Correct 15 ms 19456 KB Output is correct
4 Correct 14 ms 19456 KB Output is correct
5 Correct 14 ms 19456 KB Output is correct
6 Correct 14 ms 19456 KB Output is correct
7 Correct 16 ms 19456 KB Output is correct
8 Correct 14 ms 19456 KB Output is correct
9 Correct 16 ms 19840 KB Output is correct
10 Correct 16 ms 19712 KB Output is correct
11 Correct 16 ms 19712 KB Output is correct
12 Correct 16 ms 19712 KB Output is correct
13 Correct 16 ms 19840 KB Output is correct
14 Correct 17 ms 19840 KB Output is correct
15 Correct 16 ms 19840 KB Output is correct
16 Correct 16 ms 19840 KB Output is correct
17 Correct 900 ms 65400 KB Output is correct
18 Correct 848 ms 65400 KB Output is correct
19 Correct 860 ms 65016 KB Output is correct
20 Correct 886 ms 65016 KB Output is correct
21 Correct 983 ms 65144 KB Output is correct
22 Correct 956 ms 66424 KB Output is correct
23 Correct 966 ms 65960 KB Output is correct
24 Correct 889 ms 66424 KB Output is correct
25 Correct 999 ms 66296 KB Output is correct
26 Correct 943 ms 65612 KB Output is correct
27 Correct 907 ms 64888 KB Output is correct
28 Correct 857 ms 64908 KB Output is correct
29 Correct 892 ms 65272 KB Output is correct
30 Correct 887 ms 65400 KB Output is correct
31 Correct 908 ms 65660 KB Output is correct
32 Correct 924 ms 65912 KB Output is correct
33 Correct 755 ms 63236 KB Output is correct
34 Correct 329 ms 63136 KB Output is correct
35 Correct 514 ms 69624 KB Output is correct
36 Correct 533 ms 69580 KB Output is correct
37 Correct 527 ms 69428 KB Output is correct
38 Correct 504 ms 69752 KB Output is correct
39 Correct 510 ms 69556 KB Output is correct
40 Correct 500 ms 69892 KB Output is correct
41 Correct 513 ms 69496 KB Output is correct
42 Correct 498 ms 70008 KB Output is correct
43 Correct 491 ms 69752 KB Output is correct
44 Correct 713 ms 65468 KB Output is correct
45 Correct 503 ms 69884 KB Output is correct
46 Correct 259 ms 80632 KB Output is correct
47 Correct 250 ms 80632 KB Output is correct
48 Correct 787 ms 66080 KB Output is correct
49 Correct 794 ms 65156 KB Output is correct
50 Correct 830 ms 65312 KB Output is correct
51 Correct 341 ms 63404 KB Output is correct
52 Correct 365 ms 63240 KB Output is correct
53 Correct 368 ms 63352 KB Output is correct
54 Correct 351 ms 63276 KB Output is correct
55 Correct 838 ms 67044 KB Output is correct
56 Correct 407 ms 63336 KB Output is correct
57 Correct 591 ms 65656 KB Output is correct
58 Correct 513 ms 64768 KB Output is correct
59 Correct 535 ms 64936 KB Output is correct
60 Correct 528 ms 65944 KB Output is correct
61 Correct 536 ms 65016 KB Output is correct
62 Correct 526 ms 65316 KB Output is correct
63 Correct 510 ms 65784 KB Output is correct
64 Correct 514 ms 64888 KB Output is correct
65 Correct 511 ms 65912 KB Output is correct
66 Correct 846 ms 66184 KB Output is correct
67 Correct 514 ms 65528 KB Output is correct
68 Correct 259 ms 80896 KB Output is correct
69 Correct 259 ms 80824 KB Output is correct
70 Correct 772 ms 66268 KB Output is correct
71 Correct 752 ms 65636 KB Output is correct
72 Correct 761 ms 67044 KB Output is correct
73 Correct 379 ms 63352 KB Output is correct
74 Correct 382 ms 63480 KB Output is correct
75 Correct 379 ms 63608 KB Output is correct
76 Correct 392 ms 63412 KB Output is correct
77 Correct 853 ms 67076 KB Output is correct
78 Correct 723 ms 63428 KB Output is correct
79 Correct 683 ms 69752 KB Output is correct
80 Correct 663 ms 69368 KB Output is correct
81 Correct 612 ms 69496 KB Output is correct
82 Correct 644 ms 69240 KB Output is correct
83 Correct 652 ms 69880 KB Output is correct
84 Correct 663 ms 69876 KB Output is correct
85 Correct 604 ms 69368 KB Output is correct
86 Correct 628 ms 69496 KB Output is correct
87 Correct 650 ms 69752 KB Output is correct
88 Correct 827 ms 66028 KB Output is correct
89 Correct 631 ms 69624 KB Output is correct
90 Correct 394 ms 80504 KB Output is correct
91 Correct 381 ms 80512 KB Output is correct
92 Correct 864 ms 66280 KB Output is correct
93 Correct 822 ms 65640 KB Output is correct
94 Correct 783 ms 64872 KB Output is correct
95 Correct 619 ms 63096 KB Output is correct
96 Correct 647 ms 63096 KB Output is correct
97 Correct 635 ms 63096 KB Output is correct
98 Correct 631 ms 63036 KB Output is correct