Submission #565199

# Submission time Handle Problem Language Result Execution time Memory
565199 2022-05-20T12:42:08 Z jeff Reconstruction Project (JOI22_reconstruction) C++14
100 / 100
758 ms 32048 KB
#include <bits/stdc++.h>
using namespace std;

pair<long long, pair<long long, long long> > A[100000], l;
vector<pair<long long, pair<long long, long long> > > s;
vector<pair<long long, long long> > adj[500], f;
pair<long long, long long> r;
bool vt[500];

bool it(long long i, long long t) {
    if (i == t) return 1;
    if (vt[i]) return 0;
    vt[i] = 1;
    for (long long j = 0; j < adj[i].size(); ++j) if (it(adj[i][j].first, t)) {
        l = min(l, make_pair(adj[i][j].second, make_pair(i, adj[i][j].first)));
        return 1;
    }
    return 0;
}

int main() {
    long long N, M, Q, x, i, j;
    scanf("%lld %lld", &N, &M);
    for (i = 0; i < M; ++i) scanf("%lld %lld %lld", &A[i].second.first, &A[i].second.second, &A[i].first), --A[i].second.first, --A[i].second.second;
    sort(A, A + M);
    for (i = 0; i < M; ++i) {
        l = make_pair(LLONG_MAX, make_pair(-1, -1));
        memset(vt, 0, sizeof(vt));
        if (it(A[i].second.first, A[i].second.second)) {
            for (j = 0; j < adj[l.second.first].size(); ++j) if (adj[l.second.first][j].first != l.second.second) f.push_back(adj[l.second.first][j]);
            swap(adj[l.second.first], f);
            f.clear();
            for (j = 0; j < adj[l.second.second].size(); ++j) if (adj[l.second.second][j].first != l.second.first) f.push_back(adj[l.second.second][j]);
            swap(adj[l.second.second], f);
            f.clear();
            s.emplace_back((l.first + A[i].first + 1) / 2, make_pair(-2, l.first + A[i].first));
            s.emplace_back(A[i].first, make_pair(2, -A[i].first * 2));
            adj[A[i].second.first].emplace_back(A[i].second.second, A[i].first);
            adj[A[i].second.second].emplace_back(A[i].second.first, A[i].first);
        } else {
            r.first -= 1;
            r.second += A[i].first;
            s.emplace_back(A[i].first, make_pair(2, -A[i].first * 2));
            adj[A[i].second.first].emplace_back(A[i].second.second, A[i].first);
            adj[A[i].second.second].emplace_back(A[i].second.first, A[i].first);
        }
    }
    sort(s.begin(), s.end());
    scanf("%lld", &Q);
    for (i = j = 0; i < Q; ++i) {
        scanf("%lld", &x);
        for (j; j < s.size() && s[j].first <= x; ++j) r.first += s[j].second.first, r.second += s[j].second.second;
        printf("%lld\n", r.first * x + r.second);
    }
    return 0;
}

Compilation message

reconstruction.cpp: In function 'bool it(long long int, long long int)':
reconstruction.cpp:14:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (long long j = 0; j < adj[i].size(); ++j) if (it(adj[i][j].first, t)) {
      |                           ~~^~~~~~~~~~~~~~~
reconstruction.cpp: In function 'int main()':
reconstruction.cpp:30:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |             for (j = 0; j < adj[l.second.first].size(); ++j) if (adj[l.second.first][j].first != l.second.second) f.push_back(adj[l.second.first][j]);
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:33:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (j = 0; j < adj[l.second.second].size(); ++j) if (adj[l.second.second][j].first != l.second.first) f.push_back(adj[l.second.second][j]);
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:52:14: warning: statement has no effect [-Wunused-value]
   52 |         for (j; j < s.size() && s[j].first <= x; ++j) r.first += s[j].second.first, r.second += s[j].second.second;
      |              ^
reconstruction.cpp:52:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (j; j < s.size() && s[j].first <= x; ++j) r.first += s[j].second.first, r.second += s[j].second.second;
      |                 ~~^~~~~~~~~~
reconstruction.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%lld %lld", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:24:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     for (i = 0; i < M; ++i) scanf("%lld %lld %lld", &A[i].second.first, &A[i].second.second, &A[i].first), --A[i].second.first, --A[i].second.second;
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%lld", &Q);
      |     ~~~~~^~~~~~~~~~~~
reconstruction.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%lld", &x);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 453 ms 10620 KB Output is correct
21 Correct 247 ms 8912 KB Output is correct
22 Correct 348 ms 9016 KB Output is correct
23 Correct 390 ms 9284 KB Output is correct
24 Correct 384 ms 8992 KB Output is correct
25 Correct 468 ms 9008 KB Output is correct
26 Correct 441 ms 10708 KB Output is correct
27 Correct 464 ms 10484 KB Output is correct
28 Correct 455 ms 10664 KB Output is correct
29 Correct 379 ms 10964 KB Output is correct
30 Correct 453 ms 10800 KB Output is correct
31 Correct 448 ms 10788 KB Output is correct
32 Correct 469 ms 10608 KB Output is correct
33 Correct 447 ms 10556 KB Output is correct
34 Correct 373 ms 14648 KB Output is correct
35 Correct 466 ms 10684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 476 ms 29888 KB Output is correct
5 Correct 512 ms 29892 KB Output is correct
6 Correct 493 ms 29752 KB Output is correct
7 Correct 356 ms 31748 KB Output is correct
8 Correct 319 ms 31876 KB Output is correct
9 Correct 297 ms 31932 KB Output is correct
10 Correct 475 ms 30036 KB Output is correct
11 Correct 324 ms 32048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 275 ms 22004 KB Output is correct
21 Correct 259 ms 20156 KB Output is correct
22 Correct 249 ms 22304 KB Output is correct
23 Correct 244 ms 22416 KB Output is correct
24 Correct 242 ms 22200 KB Output is correct
25 Correct 241 ms 22256 KB Output is correct
26 Correct 255 ms 22228 KB Output is correct
27 Correct 250 ms 22296 KB Output is correct
28 Correct 266 ms 22292 KB Output is correct
29 Correct 248 ms 22356 KB Output is correct
30 Correct 272 ms 22348 KB Output is correct
31 Correct 256 ms 22092 KB Output is correct
32 Correct 257 ms 22656 KB Output is correct
33 Correct 256 ms 22100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 453 ms 10620 KB Output is correct
21 Correct 247 ms 8912 KB Output is correct
22 Correct 348 ms 9016 KB Output is correct
23 Correct 390 ms 9284 KB Output is correct
24 Correct 384 ms 8992 KB Output is correct
25 Correct 468 ms 9008 KB Output is correct
26 Correct 441 ms 10708 KB Output is correct
27 Correct 464 ms 10484 KB Output is correct
28 Correct 455 ms 10664 KB Output is correct
29 Correct 379 ms 10964 KB Output is correct
30 Correct 453 ms 10800 KB Output is correct
31 Correct 448 ms 10788 KB Output is correct
32 Correct 469 ms 10608 KB Output is correct
33 Correct 447 ms 10556 KB Output is correct
34 Correct 373 ms 14648 KB Output is correct
35 Correct 466 ms 10684 KB Output is correct
36 Correct 472 ms 10860 KB Output is correct
37 Correct 260 ms 10848 KB Output is correct
38 Correct 398 ms 10792 KB Output is correct
39 Correct 414 ms 10736 KB Output is correct
40 Correct 385 ms 10432 KB Output is correct
41 Correct 455 ms 10860 KB Output is correct
42 Correct 532 ms 10788 KB Output is correct
43 Correct 464 ms 10996 KB Output is correct
44 Correct 458 ms 10804 KB Output is correct
45 Correct 376 ms 11072 KB Output is correct
46 Correct 490 ms 10828 KB Output is correct
47 Correct 454 ms 10756 KB Output is correct
48 Correct 474 ms 10812 KB Output is correct
49 Correct 471 ms 10836 KB Output is correct
50 Correct 346 ms 14588 KB Output is correct
51 Correct 471 ms 10664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 453 ms 10620 KB Output is correct
21 Correct 247 ms 8912 KB Output is correct
22 Correct 348 ms 9016 KB Output is correct
23 Correct 390 ms 9284 KB Output is correct
24 Correct 384 ms 8992 KB Output is correct
25 Correct 468 ms 9008 KB Output is correct
26 Correct 441 ms 10708 KB Output is correct
27 Correct 464 ms 10484 KB Output is correct
28 Correct 455 ms 10664 KB Output is correct
29 Correct 379 ms 10964 KB Output is correct
30 Correct 453 ms 10800 KB Output is correct
31 Correct 448 ms 10788 KB Output is correct
32 Correct 469 ms 10608 KB Output is correct
33 Correct 447 ms 10556 KB Output is correct
34 Correct 373 ms 14648 KB Output is correct
35 Correct 466 ms 10684 KB Output is correct
36 Correct 1 ms 324 KB Output is correct
37 Correct 1 ms 316 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 476 ms 29888 KB Output is correct
40 Correct 512 ms 29892 KB Output is correct
41 Correct 493 ms 29752 KB Output is correct
42 Correct 356 ms 31748 KB Output is correct
43 Correct 319 ms 31876 KB Output is correct
44 Correct 297 ms 31932 KB Output is correct
45 Correct 475 ms 30036 KB Output is correct
46 Correct 324 ms 32048 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 275 ms 22004 KB Output is correct
49 Correct 259 ms 20156 KB Output is correct
50 Correct 249 ms 22304 KB Output is correct
51 Correct 244 ms 22416 KB Output is correct
52 Correct 242 ms 22200 KB Output is correct
53 Correct 241 ms 22256 KB Output is correct
54 Correct 255 ms 22228 KB Output is correct
55 Correct 250 ms 22296 KB Output is correct
56 Correct 266 ms 22292 KB Output is correct
57 Correct 248 ms 22356 KB Output is correct
58 Correct 272 ms 22348 KB Output is correct
59 Correct 256 ms 22092 KB Output is correct
60 Correct 257 ms 22656 KB Output is correct
61 Correct 256 ms 22100 KB Output is correct
62 Correct 472 ms 10860 KB Output is correct
63 Correct 260 ms 10848 KB Output is correct
64 Correct 398 ms 10792 KB Output is correct
65 Correct 414 ms 10736 KB Output is correct
66 Correct 385 ms 10432 KB Output is correct
67 Correct 455 ms 10860 KB Output is correct
68 Correct 532 ms 10788 KB Output is correct
69 Correct 464 ms 10996 KB Output is correct
70 Correct 458 ms 10804 KB Output is correct
71 Correct 376 ms 11072 KB Output is correct
72 Correct 490 ms 10828 KB Output is correct
73 Correct 454 ms 10756 KB Output is correct
74 Correct 474 ms 10812 KB Output is correct
75 Correct 471 ms 10836 KB Output is correct
76 Correct 346 ms 14588 KB Output is correct
77 Correct 471 ms 10664 KB Output is correct
78 Correct 725 ms 28660 KB Output is correct
79 Correct 498 ms 28572 KB Output is correct
80 Correct 636 ms 29792 KB Output is correct
81 Correct 621 ms 29864 KB Output is correct
82 Correct 613 ms 28956 KB Output is correct
83 Correct 696 ms 28360 KB Output is correct
84 Correct 709 ms 25992 KB Output is correct
85 Correct 694 ms 28684 KB Output is correct
86 Correct 689 ms 17680 KB Output is correct
87 Correct 604 ms 23796 KB Output is correct
88 Correct 725 ms 28596 KB Output is correct
89 Correct 696 ms 28552 KB Output is correct
90 Correct 758 ms 28712 KB Output is correct
91 Correct 700 ms 21276 KB Output is correct
92 Correct 573 ms 24364 KB Output is correct
93 Correct 700 ms 19348 KB Output is correct