Submission #699685

# Submission time Handle Problem Language Result Execution time Memory
699685 2023-02-17T18:56:10 Z finn__ Pipes (BOI13_pipes) C++17
65 / 100
61 ms 12336 KB
#include <bits/stdc++.h>
using namespace std;

#define N 100000
#define M 500000

vector<pair<unsigned, unsigned>> g[N];
int64_t y[N], ans[M];

int64_t solve_for_tree(unsigned u, unsigned p1 = -1, unsigned p2 = -1)
{
    int64_t val = 0;

    for (auto const &[v, i] : g[u])
        if (v != p1 && v != p2)
        {
            int64_t z = solve_for_tree(v, u);
            ans[i] = y[v] - z;
            val += ans[i];
        }

    return val;
}

int main()
{
    size_t n, m;
    scanf("%zu %zu", &n, &m);

    if (m > n)
    {
        printf("0\n");
        return 0;
    }

    for (size_t i = 0; i < n; i++)
        scanf("%" PRId64, y + i);
    for (size_t i = 0; i < m; i++)
    {
        unsigned u, v;
        scanf("%u %u", &u, &v);
        g[u - 1].emplace_back(v - 1, i);
        g[v - 1].emplace_back(u - 1, i);
    }

    if (m + 1 == n)
        solve_for_tree(0);
    else
    {
    }

    for (size_t i = 0; i < m; i++)
        printf("%" PRId64 "\n", 2 * ans[i]);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%zu %zu", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%" PRId64, y + i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%u %u", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 57 ms 9824 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 44 ms 8308 KB Output is correct
14 Correct 52 ms 9400 KB Output is correct
15 Correct 59 ms 9812 KB Output is correct
16 Correct 47 ms 8704 KB Output is correct
17 Correct 56 ms 9812 KB Output is correct
18 Correct 61 ms 9804 KB Output is correct
19 Correct 60 ms 12336 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 56 ms 9876 KB Output is correct
23 Correct 48 ms 8396 KB Output is correct
24 Correct 57 ms 9924 KB Output is correct
25 Correct 50 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Incorrect 46 ms 8200 KB Output isn't correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2600 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Incorrect 1 ms 2644 KB Output isn't correct
9 Incorrect 1 ms 2644 KB Output isn't correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Incorrect 2 ms 2644 KB Output isn't correct
15 Incorrect 2 ms 2644 KB Output isn't correct
16 Incorrect 2 ms 2644 KB Output isn't correct
17 Incorrect 2 ms 2644 KB Output isn't correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Incorrect 2 ms 2644 KB Output isn't correct
23 Incorrect 40 ms 7396 KB Output isn't correct
24 Incorrect 50 ms 8492 KB Output isn't correct
25 Incorrect 46 ms 8264 KB Output isn't correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Incorrect 47 ms 8140 KB Output isn't correct
31 Incorrect 55 ms 8320 KB Output isn't correct
32 Incorrect 49 ms 8752 KB Output isn't correct
33 Incorrect 48 ms 8496 KB Output isn't correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Incorrect 47 ms 8348 KB Output isn't correct
39 Incorrect 48 ms 8704 KB Output isn't correct
40 Incorrect 51 ms 8564 KB Output isn't correct
41 Incorrect 49 ms 8280 KB Output isn't correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Incorrect 49 ms 8196 KB Output isn't correct
47 Incorrect 49 ms 8520 KB Output isn't correct
48 Incorrect 47 ms 8272 KB Output isn't correct
49 Incorrect 48 ms 8496 KB Output isn't correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Incorrect 48 ms 8376 KB Output isn't correct