Submission #672834

# Submission time Handle Problem Language Result Execution time Memory
672834 2022-12-18T10:41:04 Z sugartheanh Aesthetic (NOI20_aesthetic) C++14
100 / 100
608 ms 41528 KB
#include <bits/stdc++.h>
using namespace std;

long long r[2][300000];
bool vt[300000], f[300000];
int A[300000][4], p[300000], q[300000], d[300000], id[300000];
vector<pair<pair<int, int>, int> > adj[300000];
priority_queue<pair<pair<long long, int>, pair<int, int> > > pq;

int frt(int i) {return i == id[i] ? i : id[i] = frt(id[i]);}

void it(int i, int t, int o, int l, long long v) {
    if (vt[i]) return;
    vt[i] = 1;
    if (!t) {p[i] = o; q[i] = l; d[i] = d[o] + !!i;}
    r[t][i] = v;
    for (int j = 0; j < adj[i].size(); ++j) if (!vt[adj[i][j].first.first]) pq.emplace(make_pair(-v - adj[i][j].first.second, adj[i][j].first.first), make_pair(i, adj[i][j].second));
}

int main() {
    //freopen("in.txt", "r", stdin);
    int N, M, a, b, x, i, j;
    long long l, h, c;
    bool e;
    scanf("%d %d", &N, &M);
    for (i = 0; i < M; ++i) {for (j = 0; j < 3; ++j) scanf("%d", &A[i][j]); adj[--A[i][0]].emplace_back(make_pair(--A[i][1], A[i][2]), i); adj[A[i][1]].emplace_back(make_pair(A[i][0], A[i][2]), i);}
    for (i = M - 2; i > -1; --i) A[i][3] = max(A[i + 1][2], A[i + 1][3]);
    it(0, 0, 0, -1, 0);
    while (!pq.empty()) x = pq.top().first.second, c = -pq.top().first.first, a = pq.top().second.first, b = pq.top().second.second, pq.pop(), it(x, 0, a, b, c);
    memset(vt, 0, sizeof(vt));
    it(N - 1, 1, N - 1, -1, 0);
    while (!pq.empty()) x = pq.top().first.second, c = -pq.top().first.first, a = pq.top().second.first, b = pq.top().second.second, pq.pop(), it(x, 1, a, b, c);
    h = (l = r[0][N - 1]) + 1000000000;
    //for (i = 0; i < M; ++i) printf("%d: %d %d %d %d\n", i, A[i][0], A[i][1], A[i][2], A[i][3]);
    while (l < h) {
        e = 0;
        c = (l + h + 1) / 2;
        //printf("%lld %lld %lld:\n", l, h, c);
        for (i = 0; i < N; ++i) {id[i] = p[i]; if (i) f[q[i]] = 1;}
        for (i = N - 1; i; i = p[i]) id[i] = i;
        for (i = 0; i < M; ++i) if (!f[i] && (r[0][A[i][0]] + A[i][2] + r[1][A[i][1]] < c || r[0][A[i][1]] + A[i][2] + r[1][A[i][0]] < c)) {
            a = frt(A[i][0]);
            b = frt(A[i][1]);
            if (d[a] > d[b]) swap(a, b);
            //printf("%d %d | %d %d\n", a, b, d[a], d[b]);
            while (a != b) id[b] = p[b], b = frt(b);
        }
        for (i = frt(N - 1); i && !e; i = frt(p[i])) e = (c <= r[0][A[q[i]][0]] + A[q[i]][2] + A[q[i]][3] + r[1][A[q[i]][1]] && c <= r[0][A[q[i]][1]] + A[q[i]][2] + A[q[i]][3] + r[1][A[q[i]][0]]);
        //for (i = frt(N - 1); i; i = frt(p[i])) printf("! %d _ %d %d %d (%d)\n", q[i], A[q[i]][0], A[q[i]][1], A[q[i]][2], A[q[i]][3]);
        (e ? l : h) = c - !e;
        //printf("\n");
    }
    printf("%lld", (l + h) / 2);
    return 0;
}

Compilation message

Aesthetic.cpp: In function 'void it(int, int, int, int, long long int)':
Aesthetic.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int j = 0; j < adj[i].size(); ++j) if (!vt[adj[i][j].first.first]) pq.emplace(make_pair(-v - adj[i][j].first.second, adj[i][j].first.first), make_pair(i, adj[i][j].second));
      |                     ~~^~~~~~~~~~~~~~~
Aesthetic.cpp: In function 'int main()':
Aesthetic.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Aesthetic.cpp:26:59: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     for (i = 0; i < M; ++i) {for (j = 0; j < 3; ++j) scanf("%d", &A[i][j]); adj[--A[i][0]].emplace_back(make_pair(--A[i][1], A[i][2]), i); adj[A[i][1]].emplace_back(make_pair(A[i][0], A[i][2]), i);}
      |                                                      ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7636 KB Output is correct
2 Correct 4 ms 7636 KB Output is correct
3 Correct 4 ms 7616 KB Output is correct
4 Correct 4 ms 7636 KB Output is correct
5 Correct 4 ms 7636 KB Output is correct
6 Correct 4 ms 7636 KB Output is correct
7 Correct 4 ms 7636 KB Output is correct
8 Correct 4 ms 7636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7636 KB Output is correct
2 Correct 4 ms 7636 KB Output is correct
3 Correct 4 ms 7616 KB Output is correct
4 Correct 4 ms 7636 KB Output is correct
5 Correct 4 ms 7636 KB Output is correct
6 Correct 4 ms 7636 KB Output is correct
7 Correct 4 ms 7636 KB Output is correct
8 Correct 4 ms 7636 KB Output is correct
9 Correct 7 ms 7892 KB Output is correct
10 Correct 6 ms 7892 KB Output is correct
11 Correct 5 ms 7756 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 6 ms 7860 KB Output is correct
14 Correct 6 ms 7764 KB Output is correct
15 Correct 5 ms 7796 KB Output is correct
16 Correct 5 ms 7764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 40640 KB Output is correct
2 Correct 448 ms 41036 KB Output is correct
3 Correct 438 ms 40376 KB Output is correct
4 Correct 443 ms 40540 KB Output is correct
5 Correct 451 ms 40568 KB Output is correct
6 Correct 470 ms 41292 KB Output is correct
7 Correct 457 ms 41140 KB Output is correct
8 Correct 461 ms 41436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 41288 KB Output is correct
2 Correct 457 ms 40896 KB Output is correct
3 Correct 445 ms 40720 KB Output is correct
4 Correct 457 ms 41528 KB Output is correct
5 Correct 441 ms 40700 KB Output is correct
6 Correct 462 ms 40960 KB Output is correct
7 Correct 460 ms 40848 KB Output is correct
8 Correct 451 ms 41080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 569 ms 37372 KB Output is correct
2 Correct 307 ms 34536 KB Output is correct
3 Correct 403 ms 31884 KB Output is correct
4 Correct 409 ms 31980 KB Output is correct
5 Correct 401 ms 31924 KB Output is correct
6 Correct 413 ms 31924 KB Output is correct
7 Correct 397 ms 31864 KB Output is correct
8 Correct 426 ms 32100 KB Output is correct
9 Correct 425 ms 32060 KB Output is correct
10 Correct 410 ms 32100 KB Output is correct
11 Correct 418 ms 31920 KB Output is correct
12 Correct 577 ms 37700 KB Output is correct
13 Correct 424 ms 32056 KB Output is correct
14 Correct 233 ms 35816 KB Output is correct
15 Correct 227 ms 37080 KB Output is correct
16 Correct 588 ms 37940 KB Output is correct
17 Correct 572 ms 37052 KB Output is correct
18 Correct 582 ms 37620 KB Output is correct
19 Correct 300 ms 34608 KB Output is correct
20 Correct 307 ms 34508 KB Output is correct
21 Correct 309 ms 34600 KB Output is correct
22 Correct 310 ms 34728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 569 ms 37372 KB Output is correct
2 Correct 307 ms 34536 KB Output is correct
3 Correct 403 ms 31884 KB Output is correct
4 Correct 409 ms 31980 KB Output is correct
5 Correct 401 ms 31924 KB Output is correct
6 Correct 413 ms 31924 KB Output is correct
7 Correct 397 ms 31864 KB Output is correct
8 Correct 426 ms 32100 KB Output is correct
9 Correct 425 ms 32060 KB Output is correct
10 Correct 410 ms 32100 KB Output is correct
11 Correct 418 ms 31920 KB Output is correct
12 Correct 577 ms 37700 KB Output is correct
13 Correct 424 ms 32056 KB Output is correct
14 Correct 233 ms 35816 KB Output is correct
15 Correct 227 ms 37080 KB Output is correct
16 Correct 588 ms 37940 KB Output is correct
17 Correct 572 ms 37052 KB Output is correct
18 Correct 582 ms 37620 KB Output is correct
19 Correct 300 ms 34608 KB Output is correct
20 Correct 307 ms 34508 KB Output is correct
21 Correct 309 ms 34600 KB Output is correct
22 Correct 310 ms 34728 KB Output is correct
23 Correct 608 ms 38080 KB Output is correct
24 Correct 329 ms 34580 KB Output is correct
25 Correct 389 ms 31848 KB Output is correct
26 Correct 416 ms 32012 KB Output is correct
27 Correct 397 ms 32028 KB Output is correct
28 Correct 416 ms 32064 KB Output is correct
29 Correct 416 ms 32184 KB Output is correct
30 Correct 395 ms 32076 KB Output is correct
31 Correct 414 ms 32240 KB Output is correct
32 Correct 417 ms 32028 KB Output is correct
33 Correct 402 ms 32220 KB Output is correct
34 Correct 605 ms 37812 KB Output is correct
35 Correct 407 ms 32408 KB Output is correct
36 Correct 286 ms 35628 KB Output is correct
37 Correct 322 ms 36544 KB Output is correct
38 Correct 585 ms 37576 KB Output is correct
39 Correct 595 ms 37400 KB Output is correct
40 Correct 597 ms 37940 KB Output is correct
41 Correct 333 ms 34636 KB Output is correct
42 Correct 325 ms 34684 KB Output is correct
43 Correct 335 ms 34668 KB Output is correct
44 Correct 333 ms 34764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7636 KB Output is correct
2 Correct 4 ms 7636 KB Output is correct
3 Correct 4 ms 7616 KB Output is correct
4 Correct 4 ms 7636 KB Output is correct
5 Correct 4 ms 7636 KB Output is correct
6 Correct 4 ms 7636 KB Output is correct
7 Correct 4 ms 7636 KB Output is correct
8 Correct 4 ms 7636 KB Output is correct
9 Correct 7 ms 7892 KB Output is correct
10 Correct 6 ms 7892 KB Output is correct
11 Correct 5 ms 7756 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 6 ms 7860 KB Output is correct
14 Correct 6 ms 7764 KB Output is correct
15 Correct 5 ms 7796 KB Output is correct
16 Correct 5 ms 7764 KB Output is correct
17 Correct 458 ms 40640 KB Output is correct
18 Correct 448 ms 41036 KB Output is correct
19 Correct 438 ms 40376 KB Output is correct
20 Correct 443 ms 40540 KB Output is correct
21 Correct 451 ms 40568 KB Output is correct
22 Correct 470 ms 41292 KB Output is correct
23 Correct 457 ms 41140 KB Output is correct
24 Correct 461 ms 41436 KB Output is correct
25 Correct 485 ms 41288 KB Output is correct
26 Correct 457 ms 40896 KB Output is correct
27 Correct 445 ms 40720 KB Output is correct
28 Correct 457 ms 41528 KB Output is correct
29 Correct 441 ms 40700 KB Output is correct
30 Correct 462 ms 40960 KB Output is correct
31 Correct 460 ms 40848 KB Output is correct
32 Correct 451 ms 41080 KB Output is correct
33 Correct 569 ms 37372 KB Output is correct
34 Correct 307 ms 34536 KB Output is correct
35 Correct 403 ms 31884 KB Output is correct
36 Correct 409 ms 31980 KB Output is correct
37 Correct 401 ms 31924 KB Output is correct
38 Correct 413 ms 31924 KB Output is correct
39 Correct 397 ms 31864 KB Output is correct
40 Correct 426 ms 32100 KB Output is correct
41 Correct 425 ms 32060 KB Output is correct
42 Correct 410 ms 32100 KB Output is correct
43 Correct 418 ms 31920 KB Output is correct
44 Correct 577 ms 37700 KB Output is correct
45 Correct 424 ms 32056 KB Output is correct
46 Correct 233 ms 35816 KB Output is correct
47 Correct 227 ms 37080 KB Output is correct
48 Correct 588 ms 37940 KB Output is correct
49 Correct 572 ms 37052 KB Output is correct
50 Correct 582 ms 37620 KB Output is correct
51 Correct 300 ms 34608 KB Output is correct
52 Correct 307 ms 34508 KB Output is correct
53 Correct 309 ms 34600 KB Output is correct
54 Correct 310 ms 34728 KB Output is correct
55 Correct 608 ms 38080 KB Output is correct
56 Correct 329 ms 34580 KB Output is correct
57 Correct 389 ms 31848 KB Output is correct
58 Correct 416 ms 32012 KB Output is correct
59 Correct 397 ms 32028 KB Output is correct
60 Correct 416 ms 32064 KB Output is correct
61 Correct 416 ms 32184 KB Output is correct
62 Correct 395 ms 32076 KB Output is correct
63 Correct 414 ms 32240 KB Output is correct
64 Correct 417 ms 32028 KB Output is correct
65 Correct 402 ms 32220 KB Output is correct
66 Correct 605 ms 37812 KB Output is correct
67 Correct 407 ms 32408 KB Output is correct
68 Correct 286 ms 35628 KB Output is correct
69 Correct 322 ms 36544 KB Output is correct
70 Correct 585 ms 37576 KB Output is correct
71 Correct 595 ms 37400 KB Output is correct
72 Correct 597 ms 37940 KB Output is correct
73 Correct 333 ms 34636 KB Output is correct
74 Correct 325 ms 34684 KB Output is correct
75 Correct 335 ms 34668 KB Output is correct
76 Correct 333 ms 34764 KB Output is correct
77 Correct 504 ms 40512 KB Output is correct
78 Correct 298 ms 36964 KB Output is correct
79 Correct 346 ms 34440 KB Output is correct
80 Correct 345 ms 34300 KB Output is correct
81 Correct 356 ms 34376 KB Output is correct
82 Correct 345 ms 34164 KB Output is correct
83 Correct 344 ms 34408 KB Output is correct
84 Correct 346 ms 34516 KB Output is correct
85 Correct 344 ms 34252 KB Output is correct
86 Correct 350 ms 34500 KB Output is correct
87 Correct 341 ms 34460 KB Output is correct
88 Correct 574 ms 39980 KB Output is correct
89 Correct 350 ms 34412 KB Output is correct
90 Correct 282 ms 36180 KB Output is correct
91 Correct 294 ms 37204 KB Output is correct
92 Correct 501 ms 40320 KB Output is correct
93 Correct 496 ms 40024 KB Output is correct
94 Correct 515 ms 39616 KB Output is correct
95 Correct 293 ms 36976 KB Output is correct
96 Correct 297 ms 36924 KB Output is correct
97 Correct 300 ms 36968 KB Output is correct
98 Correct 306 ms 37028 KB Output is correct