Submission #498682

# Submission time Handle Problem Language Result Execution time Memory
498682 2021-12-26T06:40:29 Z LittleCube Paths (BOI18_paths) C++14
70 / 100
148 ms 21268 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, M, K, color[300005], adj[300005][5], adj2[100005][32];
pii edge[300005];
ll ans;

int encode(int i)
{
    return (1 << (i - 1));
}

signed main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> N >> M >> K;
    for (int i = 1; i <= N; i++)
        cin >> color[i];
    for (int i = 1; i <= M; i++)
        cin >> edge[i].F >> edge[i].S;
    if (K >= 2)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
                ans += 2;
    }
    cerr << ans << '\n';
    if (K >= 3)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
            {
                adj[edge[i].F][color[edge[i].S]]++;
                adj[edge[i].S][color[edge[i].F]]++;
            }
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= K; j++)
                for (int k = j + 1; k <= K; k++)
                    ans += adj[i][j] * adj[i][k] * 2;
    }
    cerr << ans << '\n';
    if (K >= 4)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
                for (int j = 1; j <= K; j++)
                    for (int k = 1; k <= K; k++)
                        if (j != k && color[edge[i].F] != k && color[edge[i].S] != j)
                            ans += adj[edge[i].F][j] * adj[edge[i].S][k] * 2;
    }
    if (K >= 5)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
            {
                for (int j = 1; j <= K; j++)
                    if (color[edge[i].F] != j)
                        adj2[edge[i].F][encode(color[edge[i].F]) ^ encode(color[edge[i].S]) ^ encode(j)] += adj[edge[i].S][j];
                for (int j = 1; j <= K; j++)
                    if (color[edge[i].S] != j)
                        adj2[edge[i].S][encode(color[edge[i].F]) ^ encode(color[edge[i].S]) ^ encode(j)] += adj[edge[i].F][j];
            }
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= K; j++)
                if (j != color[i])
                    for (int k = j + 1; k <= K; k++)
                        if (k != color[i] && k != j)
                            ans += adj[i][encode(color[i]) ^ j ^ k] * adj[i][31 ^ j ^ k] * 2;
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4472 KB Output is correct
2 Correct 41 ms 4288 KB Output is correct
3 Correct 99 ms 17956 KB Output is correct
4 Correct 67 ms 4204 KB Output is correct
5 Correct 50 ms 4368 KB Output is correct
6 Correct 77 ms 13380 KB Output is correct
7 Correct 109 ms 21268 KB Output is correct
8 Correct 100 ms 21132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 46 ms 4472 KB Output is correct
12 Correct 41 ms 4288 KB Output is correct
13 Correct 99 ms 17956 KB Output is correct
14 Correct 67 ms 4204 KB Output is correct
15 Correct 50 ms 4368 KB Output is correct
16 Correct 77 ms 13380 KB Output is correct
17 Correct 109 ms 21268 KB Output is correct
18 Correct 100 ms 21132 KB Output is correct
19 Correct 54 ms 5660 KB Output is correct
20 Correct 45 ms 4948 KB Output is correct
21 Correct 91 ms 21196 KB Output is correct
22 Correct 51 ms 6240 KB Output is correct
23 Correct 51 ms 6196 KB Output is correct
24 Correct 76 ms 16088 KB Output is correct
25 Correct 93 ms 21192 KB Output is correct
26 Correct 84 ms 21100 KB Output is correct
27 Correct 56 ms 4936 KB Output is correct
28 Correct 72 ms 5852 KB Output is correct
29 Correct 148 ms 21188 KB Output is correct
30 Correct 97 ms 13920 KB Output is correct
31 Correct 110 ms 13540 KB Output is correct
32 Correct 133 ms 21148 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 32 ms 1924 KB Output isn't correct
3 Halted 0 ms 0 KB -