답안 #1043304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043304 2024-08-04T08:01:38 Z vjudge1 철인 이종 경기 (APIO18_duathlon) C++17
47 / 100
645 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

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

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

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

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

void dfs_up(ll v, ll p = -1){
    for (ll 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 (ll i = 0; i < m; i ++){
        ll u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

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

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

        for (ll c = 1; c <= n; c ++){
            for (ll s = 1; s <= n; s ++){
                for (ll f = 1; f <= n; f ++){
                    if (c == s or c == f or s == f) continue;
                    bool bad = 0;
                    for (ll 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 (ll v = 1; v <= n; v ++){
        if (vis[v]) continue;
        comp.clear();
        dfs(v);
        ll edges = 0;
        for (ll 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 (ll u : comp)
            ans += dp[u] * 2;
    }

    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 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 2652 KB Output is correct
10 Correct 1 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 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2760 KB Output is correct
16 Correct 1 ms 2832 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 3676 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2800 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 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 2652 KB Output is correct
10 Correct 1 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 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2760 KB Output is correct
16 Correct 1 ms 2832 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 3676 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2800 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 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 6 ms 2908 KB Output is correct
37 Correct 6 ms 2908 KB Output is correct
38 Correct 18 ms 3164 KB Output is correct
39 Correct 27 ms 3264 KB Output is correct
40 Correct 35 ms 3164 KB Output is correct
41 Correct 5 ms 2988 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 5 ms 3004 KB Output is correct
44 Correct 5 ms 3004 KB Output is correct
45 Correct 5 ms 2908 KB Output is correct
46 Correct 5 ms 2908 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 3016 KB Output is correct
50 Correct 5 ms 2904 KB Output is correct
51 Correct 22 ms 3144 KB Output is correct
52 Correct 25 ms 3164 KB Output is correct
53 Correct 26 ms 3164 KB Output is correct
54 Correct 27 ms 3164 KB Output is correct
55 Correct 25 ms 3124 KB Output is correct
56 Correct 26 ms 3932 KB Output is correct
57 Correct 23 ms 3204 KB Output is correct
58 Correct 26 ms 3240 KB Output is correct
59 Correct 18 ms 3232 KB Output is correct
60 Correct 14 ms 3928 KB Output is correct
61 Correct 9 ms 3932 KB Output is correct
62 Correct 7 ms 3184 KB Output is correct
63 Correct 21 ms 3208 KB Output is correct
64 Correct 22 ms 3268 KB Output is correct
65 Correct 23 ms 3172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 17100 KB Output is correct
2 Correct 46 ms 17100 KB Output is correct
3 Correct 46 ms 12752 KB Output is correct
4 Correct 46 ms 15056 KB Output is correct
5 Correct 45 ms 11476 KB Output is correct
6 Correct 52 ms 11476 KB Output is correct
7 Correct 44 ms 10196 KB Output is correct
8 Correct 48 ms 11020 KB Output is correct
9 Correct 45 ms 9428 KB Output is correct
10 Correct 47 ms 10168 KB Output is correct
11 Correct 35 ms 8388 KB Output is correct
12 Correct 34 ms 8284 KB Output is correct
13 Correct 32 ms 8276 KB Output is correct
14 Correct 33 ms 8020 KB Output is correct
15 Correct 25 ms 7788 KB Output is correct
16 Correct 25 ms 6736 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 3 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 3676 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 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 2832 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 3676 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 3676 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 3932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 9116 KB Output is correct
2 Correct 45 ms 10440 KB Output is correct
3 Correct 46 ms 10440 KB Output is correct
4 Correct 45 ms 11464 KB Output is correct
5 Correct 43 ms 11408 KB Output is correct
6 Correct 48 ms 15060 KB Output is correct
7 Correct 47 ms 14032 KB Output is correct
8 Correct 52 ms 13192 KB Output is correct
9 Correct 47 ms 12752 KB Output is correct
10 Correct 43 ms 10908 KB Output is correct
11 Correct 44 ms 11468 KB Output is correct
12 Correct 45 ms 10700 KB Output is correct
13 Correct 46 ms 10672 KB Output is correct
14 Correct 45 ms 9908 KB Output is correct
15 Correct 34 ms 9552 KB Output is correct
16 Correct 26 ms 8280 KB Output is correct
17 Correct 37 ms 11312 KB Output is correct
18 Correct 45 ms 11484 KB Output is correct
19 Correct 38 ms 11320 KB Output is correct
20 Correct 36 ms 11460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Runtime error 510 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 10960 KB Output is correct
2 Correct 48 ms 11256 KB Output is correct
3 Runtime error 645 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 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 2652 KB Output is correct
10 Correct 1 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 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2760 KB Output is correct
16 Correct 1 ms 2832 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 3676 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2800 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 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 6 ms 2908 KB Output is correct
37 Correct 6 ms 2908 KB Output is correct
38 Correct 18 ms 3164 KB Output is correct
39 Correct 27 ms 3264 KB Output is correct
40 Correct 35 ms 3164 KB Output is correct
41 Correct 5 ms 2988 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 5 ms 3004 KB Output is correct
44 Correct 5 ms 3004 KB Output is correct
45 Correct 5 ms 2908 KB Output is correct
46 Correct 5 ms 2908 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 3016 KB Output is correct
50 Correct 5 ms 2904 KB Output is correct
51 Correct 22 ms 3144 KB Output is correct
52 Correct 25 ms 3164 KB Output is correct
53 Correct 26 ms 3164 KB Output is correct
54 Correct 27 ms 3164 KB Output is correct
55 Correct 25 ms 3124 KB Output is correct
56 Correct 26 ms 3932 KB Output is correct
57 Correct 23 ms 3204 KB Output is correct
58 Correct 26 ms 3240 KB Output is correct
59 Correct 18 ms 3232 KB Output is correct
60 Correct 14 ms 3928 KB Output is correct
61 Correct 9 ms 3932 KB Output is correct
62 Correct 7 ms 3184 KB Output is correct
63 Correct 21 ms 3208 KB Output is correct
64 Correct 22 ms 3268 KB Output is correct
65 Correct 23 ms 3172 KB Output is correct
66 Correct 1 ms 3676 KB Output is correct
67 Correct 1 ms 2652 KB Output is correct
68 Runtime error 502 ms 1048576 KB Execution killed with signal 9
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3676 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 2652 KB Output is correct
10 Correct 1 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 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2760 KB Output is correct
16 Correct 1 ms 2832 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 3676 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2800 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 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 6 ms 2908 KB Output is correct
37 Correct 6 ms 2908 KB Output is correct
38 Correct 18 ms 3164 KB Output is correct
39 Correct 27 ms 3264 KB Output is correct
40 Correct 35 ms 3164 KB Output is correct
41 Correct 5 ms 2988 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 5 ms 3004 KB Output is correct
44 Correct 5 ms 3004 KB Output is correct
45 Correct 5 ms 2908 KB Output is correct
46 Correct 5 ms 2908 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 3016 KB Output is correct
50 Correct 5 ms 2904 KB Output is correct
51 Correct 22 ms 3144 KB Output is correct
52 Correct 25 ms 3164 KB Output is correct
53 Correct 26 ms 3164 KB Output is correct
54 Correct 27 ms 3164 KB Output is correct
55 Correct 25 ms 3124 KB Output is correct
56 Correct 26 ms 3932 KB Output is correct
57 Correct 23 ms 3204 KB Output is correct
58 Correct 26 ms 3240 KB Output is correct
59 Correct 18 ms 3232 KB Output is correct
60 Correct 14 ms 3928 KB Output is correct
61 Correct 9 ms 3932 KB Output is correct
62 Correct 7 ms 3184 KB Output is correct
63 Correct 21 ms 3208 KB Output is correct
64 Correct 22 ms 3268 KB Output is correct
65 Correct 23 ms 3172 KB Output is correct
66 Correct 49 ms 17100 KB Output is correct
67 Correct 46 ms 17100 KB Output is correct
68 Correct 46 ms 12752 KB Output is correct
69 Correct 46 ms 15056 KB Output is correct
70 Correct 45 ms 11476 KB Output is correct
71 Correct 52 ms 11476 KB Output is correct
72 Correct 44 ms 10196 KB Output is correct
73 Correct 48 ms 11020 KB Output is correct
74 Correct 45 ms 9428 KB Output is correct
75 Correct 47 ms 10168 KB Output is correct
76 Correct 35 ms 8388 KB Output is correct
77 Correct 34 ms 8284 KB Output is correct
78 Correct 32 ms 8276 KB Output is correct
79 Correct 33 ms 8020 KB Output is correct
80 Correct 25 ms 7788 KB Output is correct
81 Correct 25 ms 6736 KB Output is correct
82 Correct 2 ms 4444 KB Output is correct
83 Correct 2 ms 4444 KB Output is correct
84 Correct 3 ms 4444 KB Output is correct
85 Correct 2 ms 4444 KB Output is correct
86 Correct 2 ms 4444 KB Output is correct
87 Correct 2 ms 5212 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 3676 KB Output is correct
91 Correct 1 ms 2908 KB Output is correct
92 Correct 1 ms 2908 KB Output is correct
93 Correct 1 ms 2652 KB Output is correct
94 Correct 1 ms 2652 KB Output is correct
95 Correct 1 ms 2832 KB Output is correct
96 Correct 1 ms 2652 KB Output is correct
97 Correct 1 ms 2652 KB Output is correct
98 Correct 1 ms 2648 KB Output is correct
99 Correct 1 ms 3676 KB Output is correct
100 Correct 1 ms 2652 KB Output is correct
101 Correct 1 ms 2652 KB Output is correct
102 Correct 1 ms 3676 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 2652 KB Output is correct
106 Correct 1 ms 2652 KB Output is correct
107 Correct 1 ms 3932 KB Output is correct
108 Correct 48 ms 9116 KB Output is correct
109 Correct 45 ms 10440 KB Output is correct
110 Correct 46 ms 10440 KB Output is correct
111 Correct 45 ms 11464 KB Output is correct
112 Correct 43 ms 11408 KB Output is correct
113 Correct 48 ms 15060 KB Output is correct
114 Correct 47 ms 14032 KB Output is correct
115 Correct 52 ms 13192 KB Output is correct
116 Correct 47 ms 12752 KB Output is correct
117 Correct 43 ms 10908 KB Output is correct
118 Correct 44 ms 11468 KB Output is correct
119 Correct 45 ms 10700 KB Output is correct
120 Correct 46 ms 10672 KB Output is correct
121 Correct 45 ms 9908 KB Output is correct
122 Correct 34 ms 9552 KB Output is correct
123 Correct 26 ms 8280 KB Output is correct
124 Correct 37 ms 11312 KB Output is correct
125 Correct 45 ms 11484 KB Output is correct
126 Correct 38 ms 11320 KB Output is correct
127 Correct 36 ms 11460 KB Output is correct
128 Correct 1 ms 3676 KB Output is correct
129 Correct 1 ms 2652 KB Output is correct
130 Runtime error 510 ms 1048576 KB Execution killed with signal 9
131 Halted 0 ms 0 KB -