Submission #1043303

# Submission time Handle Problem Language Result Execution time Memory
1043303 2024-08-04T08:01:15 Z vjudge1 Duathlon (APIO18_duathlon) C++17
34 / 100
559 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 1e5 + 10;
int n, m, subsz[N], dp[N];
vector<int> g[N], comp;
bool vis[N], possible[105][105][105];

void dfs_brute(int v, int y, int z){
    if (v == z) return;
    vis[v] = 1;
    for (int u : g[v])
        if (!vis[u]) dfs_brute(u, y, z);
}

void dfs(int v, int p = -1){
    vis[v] = 1;
    comp.push_back(v);
    subsz[v] = 1;
    for (int u : g[v]){
        if (vis[u]) continue;
        dfs(u, v);
        subsz[v] += subsz[u];
    }

    int cur = 0;
    for (int u : g[v]){
        if (u == p) continue;
        dp[v] += subsz[u] * cur;
        cur += subsz[u];
    }
}

void dfs_up(int v, int p = -1){
    for (int u : g[v]){
        if (u == p) continue;
        dfs_up(u, v);
    }

    dp[v] += (comp.size() - subsz[v]) * (subsz[v] - 1);
}

int main(){
    cin >> n >> m;
    for (int i = 0; i < m; i ++){
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int total = n * (n - 1) * (n - 2);

    if (n <= 100 and m <= 100){
        for (int u = 1; u <= n; u ++){
            for (int v = 1; v <= n; v ++){
                for (int e = 1; e <= n; e ++){
                    for (int x = 1; x <= n; x ++)
                        vis[x] = 0;
                    dfs_brute(u, v, e);
                    if (vis[v])
                        possible[u][v][e] = 1;
                }
            }
        }

        for (int c = 1; c <= n; c ++){
            for (int s = 1; s <= n; s ++){
                for (int f = 1; f <= n; f ++){
                    if (c == s or c == f or s == f) continue;
                    bool bad = 0;
                    for (int v = 1; v <= n; v ++){
                        if (v == c) continue;
                        if (!possible[s][c][v] and !possible[c][f][v])
                            bad = 1;
                    }
                    total -= bad;
                }
            }
        }

        cout << total << endl;
        return 0;
    }

    ll ans = 0;
    for (int v = 1; v <= n; v ++){
        if (vis[v]) continue;
        comp.clear();
        dfs(v);
        int edges = 0;
        for (int x : comp)
            edges += g[x].size();
        edges /= 2;

        ll nodes = comp.size();
        if (nodes == edges){
            ans += nodes * (nodes - 1) * (nodes - 2);
            continue;
        }

        dfs_up(v);
        for (int u : comp)
            ans += dp[u] * 2;
    }

    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2728 KB Output is correct
11 Correct 1 ms 3676 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2736 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2728 KB Output is correct
11 Correct 1 ms 3676 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2736 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 5 ms 2908 KB Output is correct
37 Correct 6 ms 3112 KB Output is correct
38 Correct 20 ms 3052 KB Output is correct
39 Correct 28 ms 3932 KB Output is correct
40 Correct 36 ms 3164 KB Output is correct
41 Correct 5 ms 3672 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 5 ms 2908 KB Output is correct
44 Correct 6 ms 2944 KB Output is correct
45 Correct 6 ms 2904 KB Output is correct
46 Correct 5 ms 2992 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 5 ms 2908 KB Output is correct
49 Correct 5 ms 2908 KB Output is correct
50 Correct 6 ms 2908 KB Output is correct
51 Correct 26 ms 3040 KB Output is correct
52 Correct 27 ms 3040 KB Output is correct
53 Correct 34 ms 3160 KB Output is correct
54 Correct 26 ms 3164 KB Output is correct
55 Correct 29 ms 3932 KB Output is correct
56 Correct 29 ms 3928 KB Output is correct
57 Correct 25 ms 3224 KB Output is correct
58 Correct 27 ms 3128 KB Output is correct
59 Correct 19 ms 3164 KB Output is correct
60 Correct 14 ms 3160 KB Output is correct
61 Correct 10 ms 3164 KB Output is correct
62 Correct 7 ms 3164 KB Output is correct
63 Correct 22 ms 3164 KB Output is correct
64 Correct 24 ms 3112 KB Output is correct
65 Correct 23 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 14988 KB Output is correct
2 Correct 45 ms 15000 KB Output is correct
3 Correct 46 ms 11004 KB Output is correct
4 Correct 50 ms 15048 KB Output is correct
5 Correct 45 ms 11732 KB Output is correct
6 Correct 44 ms 11736 KB Output is correct
7 Correct 46 ms 10580 KB Output is correct
8 Correct 46 ms 11224 KB Output is correct
9 Correct 43 ms 9760 KB Output is correct
10 Correct 45 ms 10680 KB Output is correct
11 Correct 40 ms 8672 KB Output is correct
12 Correct 37 ms 7508 KB Output is correct
13 Correct 33 ms 8540 KB Output is correct
14 Correct 33 ms 8284 KB Output is correct
15 Correct 25 ms 6780 KB Output is correct
16 Correct 29 ms 7636 KB Output is correct
17 Correct 3 ms 3672 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 3572 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3672 KB Output is correct
22 Correct 3 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 2 ms 2908 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 3676 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 7328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2756 KB Output is correct
3 Runtime error 521 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 8300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2728 KB Output is correct
11 Correct 1 ms 3676 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2736 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 5 ms 2908 KB Output is correct
37 Correct 6 ms 3112 KB Output is correct
38 Correct 20 ms 3052 KB Output is correct
39 Correct 28 ms 3932 KB Output is correct
40 Correct 36 ms 3164 KB Output is correct
41 Correct 5 ms 3672 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 5 ms 2908 KB Output is correct
44 Correct 6 ms 2944 KB Output is correct
45 Correct 6 ms 2904 KB Output is correct
46 Correct 5 ms 2992 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 5 ms 2908 KB Output is correct
49 Correct 5 ms 2908 KB Output is correct
50 Correct 6 ms 2908 KB Output is correct
51 Correct 26 ms 3040 KB Output is correct
52 Correct 27 ms 3040 KB Output is correct
53 Correct 34 ms 3160 KB Output is correct
54 Correct 26 ms 3164 KB Output is correct
55 Correct 29 ms 3932 KB Output is correct
56 Correct 29 ms 3928 KB Output is correct
57 Correct 25 ms 3224 KB Output is correct
58 Correct 27 ms 3128 KB Output is correct
59 Correct 19 ms 3164 KB Output is correct
60 Correct 14 ms 3160 KB Output is correct
61 Correct 10 ms 3164 KB Output is correct
62 Correct 7 ms 3164 KB Output is correct
63 Correct 22 ms 3164 KB Output is correct
64 Correct 24 ms 3112 KB Output is correct
65 Correct 23 ms 3164 KB Output is correct
66 Correct 1 ms 2652 KB Output is correct
67 Correct 1 ms 2652 KB Output is correct
68 Runtime error 559 ms 1048576 KB Execution killed with signal 9
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3672 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2728 KB Output is correct
11 Correct 1 ms 3676 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2736 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 2 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 5 ms 2908 KB Output is correct
37 Correct 6 ms 3112 KB Output is correct
38 Correct 20 ms 3052 KB Output is correct
39 Correct 28 ms 3932 KB Output is correct
40 Correct 36 ms 3164 KB Output is correct
41 Correct 5 ms 3672 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 5 ms 2908 KB Output is correct
44 Correct 6 ms 2944 KB Output is correct
45 Correct 6 ms 2904 KB Output is correct
46 Correct 5 ms 2992 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 5 ms 2908 KB Output is correct
49 Correct 5 ms 2908 KB Output is correct
50 Correct 6 ms 2908 KB Output is correct
51 Correct 26 ms 3040 KB Output is correct
52 Correct 27 ms 3040 KB Output is correct
53 Correct 34 ms 3160 KB Output is correct
54 Correct 26 ms 3164 KB Output is correct
55 Correct 29 ms 3932 KB Output is correct
56 Correct 29 ms 3928 KB Output is correct
57 Correct 25 ms 3224 KB Output is correct
58 Correct 27 ms 3128 KB Output is correct
59 Correct 19 ms 3164 KB Output is correct
60 Correct 14 ms 3160 KB Output is correct
61 Correct 10 ms 3164 KB Output is correct
62 Correct 7 ms 3164 KB Output is correct
63 Correct 22 ms 3164 KB Output is correct
64 Correct 24 ms 3112 KB Output is correct
65 Correct 23 ms 3164 KB Output is correct
66 Correct 44 ms 14988 KB Output is correct
67 Correct 45 ms 15000 KB Output is correct
68 Correct 46 ms 11004 KB Output is correct
69 Correct 50 ms 15048 KB Output is correct
70 Correct 45 ms 11732 KB Output is correct
71 Correct 44 ms 11736 KB Output is correct
72 Correct 46 ms 10580 KB Output is correct
73 Correct 46 ms 11224 KB Output is correct
74 Correct 43 ms 9760 KB Output is correct
75 Correct 45 ms 10680 KB Output is correct
76 Correct 40 ms 8672 KB Output is correct
77 Correct 37 ms 7508 KB Output is correct
78 Correct 33 ms 8540 KB Output is correct
79 Correct 33 ms 8284 KB Output is correct
80 Correct 25 ms 6780 KB Output is correct
81 Correct 29 ms 7636 KB Output is correct
82 Correct 3 ms 3672 KB Output is correct
83 Correct 2 ms 4444 KB Output is correct
84 Correct 2 ms 3572 KB Output is correct
85 Correct 2 ms 3676 KB Output is correct
86 Correct 2 ms 3672 KB Output is correct
87 Correct 3 ms 3676 KB Output is correct
88 Correct 1 ms 2652 KB Output is correct
89 Correct 1 ms 2652 KB Output is correct
90 Correct 1 ms 2652 KB Output is correct
91 Correct 1 ms 2908 KB Output is correct
92 Correct 1 ms 3932 KB Output is correct
93 Correct 1 ms 2652 KB Output is correct
94 Correct 2 ms 2908 KB Output is correct
95 Correct 1 ms 2652 KB Output is correct
96 Correct 1 ms 2652 KB Output is correct
97 Correct 2 ms 2652 KB Output is correct
98 Correct 1 ms 2652 KB Output is correct
99 Correct 1 ms 2652 KB Output is correct
100 Correct 2 ms 3676 KB Output is correct
101 Correct 1 ms 2652 KB Output is correct
102 Correct 1 ms 2652 KB Output is correct
103 Correct 1 ms 2652 KB Output is correct
104 Correct 1 ms 2652 KB Output is correct
105 Correct 1 ms 3676 KB Output is correct
106 Correct 1 ms 2652 KB Output is correct
107 Correct 2 ms 2652 KB Output is correct
108 Incorrect 45 ms 7328 KB Output isn't correct
109 Halted 0 ms 0 KB -