Submission #1000443

# Submission time Handle Problem Language Result Execution time Memory
1000443 2024-06-17T14:01:04 Z 12345678 JOI tour (JOI24_joitour) C++17
20 / 100
3000 ms 38788 KB
#include "joitour.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=2e5+5;

ll n, t[nx], cnt[3], dp[3][nx], res;
vector<int> d[nx];

void dfs(int u, int p)
{
    dp[0][u]=dp[1][u]=dp[2][u]=0;
    dp[t[u]][u]++;
    for (auto v:d[u]) if (v!=p) dfs(v, u), dp[0][u]+=dp[0][v], dp[1][u]+=dp[1][v], dp[2][u]+=dp[2][v];
    if (t[u]==1)
    {
        ll a=0, b=0;
        for (auto v:d[u])
        {
            if (v==p) continue;
            res+=dp[0][v]*b;
            res+=dp[2][v]*a;
            b+=dp[2][v];
            a+=dp[0][v];
        }
        //cout<<"here "<<u<<' '<<res<<'\n';
        res+=dp[0][u]*(cnt[2]-dp[2][u]);
        res+=dp[2][u]*(cnt[0]-dp[0][u]);
    }
}

void init(int N, std::vector<int> F, std::vector<int> U, std::vector<int> V, int Q) 
{
    n=N;
    for (int i=0; i<n; i++) t[i]=F[i], cnt[t[i]]++;
    for (int i=0; i<n-1; i++) d[U[i]].push_back(V[i]), d[V[i]].push_back(U[i]);
}

void change(int X, int Y) 
{
    cnt[t[X]]--;
    t[X]=Y;
    cnt[t[X]]++;
}

long long num_tours() 
{
    res=0;
    dfs(0, 0);
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 1 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 1 ms 10840 KB Output is correct
13 Correct 1 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 3 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10836 KB Output is correct
20 Correct 3 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 1 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 1 ms 10840 KB Output is correct
13 Correct 1 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 3 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10836 KB Output is correct
20 Correct 3 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
25 Correct 103 ms 11096 KB Output is correct
26 Correct 71 ms 11096 KB Output is correct
27 Correct 52 ms 11096 KB Output is correct
28 Correct 53 ms 11352 KB Output is correct
29 Correct 57 ms 11096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 94 ms 31084 KB Output is correct
3 Correct 81 ms 30576 KB Output is correct
4 Correct 91 ms 27248 KB Output is correct
5 Correct 89 ms 31776 KB Output is correct
6 Correct 51 ms 20076 KB Output is correct
7 Correct 50 ms 20128 KB Output is correct
8 Correct 92 ms 20124 KB Output is correct
9 Correct 72 ms 20076 KB Output is correct
10 Correct 70 ms 20128 KB Output is correct
11 Correct 73 ms 20512 KB Output is correct
12 Correct 103 ms 25376 KB Output is correct
13 Correct 75 ms 25452 KB Output is correct
14 Correct 112 ms 25140 KB Output is correct
15 Correct 105 ms 24444 KB Output is correct
16 Correct 112 ms 34592 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10836 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 1 ms 10840 KB Output is correct
21 Correct 73 ms 20308 KB Output is correct
22 Correct 71 ms 20120 KB Output is correct
23 Correct 80 ms 20128 KB Output is correct
24 Correct 105 ms 20304 KB Output is correct
25 Correct 58 ms 20960 KB Output is correct
26 Correct 59 ms 21008 KB Output is correct
27 Correct 57 ms 20936 KB Output is correct
28 Correct 66 ms 21004 KB Output is correct
29 Correct 66 ms 38760 KB Output is correct
30 Correct 63 ms 38688 KB Output is correct
31 Correct 86 ms 38688 KB Output is correct
32 Correct 62 ms 38688 KB Output is correct
33 Correct 49 ms 20048 KB Output is correct
34 Correct 53 ms 20128 KB Output is correct
35 Correct 49 ms 20048 KB Output is correct
36 Correct 51 ms 20048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 49 ms 11352 KB Output is correct
9 Correct 64 ms 38688 KB Output is correct
10 Correct 61 ms 38764 KB Output is correct
11 Correct 63 ms 38788 KB Output is correct
12 Correct 71 ms 38688 KB Output is correct
13 Execution timed out 3024 ms 24508 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10856 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 4 ms 10840 KB Output is correct
7 Correct 52 ms 11096 KB Output is correct
8 Correct 60 ms 20124 KB Output is correct
9 Correct 54 ms 20136 KB Output is correct
10 Correct 53 ms 20120 KB Output is correct
11 Correct 49 ms 20228 KB Output is correct
12 Execution timed out 3091 ms 15040 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 1 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 1 ms 10840 KB Output is correct
13 Correct 1 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 3 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10836 KB Output is correct
20 Correct 3 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
25 Correct 103 ms 11096 KB Output is correct
26 Correct 71 ms 11096 KB Output is correct
27 Correct 52 ms 11096 KB Output is correct
28 Correct 53 ms 11352 KB Output is correct
29 Correct 57 ms 11096 KB Output is correct
30 Execution timed out 3097 ms 18368 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 1 ms 10840 KB Output is correct
4 Correct 3 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 1 ms 10840 KB Output is correct
13 Correct 1 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 2 ms 10840 KB Output is correct
16 Correct 3 ms 10840 KB Output is correct
17 Correct 2 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10836 KB Output is correct
20 Correct 3 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10840 KB Output is correct
25 Correct 103 ms 11096 KB Output is correct
26 Correct 71 ms 11096 KB Output is correct
27 Correct 52 ms 11096 KB Output is correct
28 Correct 53 ms 11352 KB Output is correct
29 Correct 57 ms 11096 KB Output is correct
30 Correct 1 ms 10840 KB Output is correct
31 Correct 94 ms 31084 KB Output is correct
32 Correct 81 ms 30576 KB Output is correct
33 Correct 91 ms 27248 KB Output is correct
34 Correct 89 ms 31776 KB Output is correct
35 Correct 51 ms 20076 KB Output is correct
36 Correct 50 ms 20128 KB Output is correct
37 Correct 92 ms 20124 KB Output is correct
38 Correct 72 ms 20076 KB Output is correct
39 Correct 70 ms 20128 KB Output is correct
40 Correct 73 ms 20512 KB Output is correct
41 Correct 103 ms 25376 KB Output is correct
42 Correct 75 ms 25452 KB Output is correct
43 Correct 112 ms 25140 KB Output is correct
44 Correct 105 ms 24444 KB Output is correct
45 Correct 112 ms 34592 KB Output is correct
46 Correct 2 ms 10840 KB Output is correct
47 Correct 2 ms 10836 KB Output is correct
48 Correct 2 ms 10840 KB Output is correct
49 Correct 1 ms 10840 KB Output is correct
50 Correct 73 ms 20308 KB Output is correct
51 Correct 71 ms 20120 KB Output is correct
52 Correct 80 ms 20128 KB Output is correct
53 Correct 105 ms 20304 KB Output is correct
54 Correct 58 ms 20960 KB Output is correct
55 Correct 59 ms 21008 KB Output is correct
56 Correct 57 ms 20936 KB Output is correct
57 Correct 66 ms 21004 KB Output is correct
58 Correct 66 ms 38760 KB Output is correct
59 Correct 63 ms 38688 KB Output is correct
60 Correct 86 ms 38688 KB Output is correct
61 Correct 62 ms 38688 KB Output is correct
62 Correct 49 ms 20048 KB Output is correct
63 Correct 53 ms 20128 KB Output is correct
64 Correct 49 ms 20048 KB Output is correct
65 Correct 51 ms 20048 KB Output is correct
66 Correct 1 ms 10840 KB Output is correct
67 Correct 1 ms 10840 KB Output is correct
68 Correct 2 ms 10840 KB Output is correct
69 Correct 2 ms 10840 KB Output is correct
70 Correct 2 ms 10840 KB Output is correct
71 Correct 2 ms 10840 KB Output is correct
72 Correct 3 ms 10840 KB Output is correct
73 Correct 49 ms 11352 KB Output is correct
74 Correct 64 ms 38688 KB Output is correct
75 Correct 61 ms 38764 KB Output is correct
76 Correct 63 ms 38788 KB Output is correct
77 Correct 71 ms 38688 KB Output is correct
78 Execution timed out 3024 ms 24508 KB Time limit exceeded
79 Halted 0 ms 0 KB -