Submission #107294

# Submission time Handle Problem Language Result Execution time Memory
107294 2019-04-23T07:07:01 Z kuroni Duathlon (APIO18_duathlon) C++14
31 / 100
392 ms 35876 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 100005;

int n, m, u, v, nod, cnt = 0, sz[2 * N], sub[2 * N], num[N], low[N];
long long ans = 0;
bool vis[2 * N];
vector<int> st, com[N], adj[N], cut[2 * N];
vector<vector<int>> bi;

void process(vector<int> &ve)
{
    sort(ve.begin(), ve.end());
    ve.erase(unique(ve.begin(), ve.end()), ve.end());
    ++nod;
    for (int &v : ve)
    {
        sz[nod]++;
        com[v].push_back(nod);
    }
}

void DFS(int u, int p = 0)
{
    low[u] = num[u] = ++cnt;
    for (int &v : adj[u])
        if (v != p)
        {
            if (num[v] > 0)
                low[u] = min(low[u], num[v]);
            else
            {
                st.push_back(u);
                DFS(v, u);
                low[u] = min(low[u], low[v]);
                if (low[v] >= num[u])
                {
                    int v; bi.push_back({});
                    do
                    {
                        v = st.back(); st.pop_back();
                        bi.back().push_back(v);
                    } while (u != v);
                    process(bi.back());
                }
            }
        }
    st.push_back(u);
}

int get_subtree(int u, int p = 0)
{
    sub[u] = sz[u];
    for (int &v : cut[u])
        if (v != p)
            sub[u] += get_subtree(v, u);
    return sub[u];
}

void find_ans(int u, int tot)
{
    vis[u] = true;
    ans += 1LL * sz[u] * (sz[u] - 1) * (sz[u] - 2);
    ans += 2LL * sz[u] * (sz[u] - 1) * (tot - sz[u]);
    int cur = tot - sub[u];
    for (int &v : cut[u])
        if (!vis[v])
        {
            find_ans(v, tot);
            ans += 2LL * cur * sz[u] * sub[v];
            cur += sub[v];
        }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    nod = n;
    while (m--)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
        if (num[i] == 0)
            DFS(i);
    for (int i = 1; i <= n; i++)
        if (com[i].size() > 1)
        {
            sz[i] = 1;
            for (int &v : com[i])
            {
                sz[v]--;
                cut[i].push_back(v);
                cut[v].push_back(i);
            }
        }
    for (int i = 1; i <= nod; i++)
        if (!vis[i])
            find_ans(i, get_subtree(i));
    for (int i = n + 1; i <= nod; i++)
    {
        int ver = cut[i].size();
        ans += 1LL * ver * (sz[i] + ver - 1) * (sz[i] + ver - 2);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 15 ms 9828 KB Output is correct
3 Correct 12 ms 9600 KB Output is correct
4 Correct 14 ms 9728 KB Output is correct
5 Correct 15 ms 9728 KB Output is correct
6 Correct 13 ms 9728 KB Output is correct
7 Incorrect 12 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 15 ms 9828 KB Output is correct
3 Correct 12 ms 9600 KB Output is correct
4 Correct 14 ms 9728 KB Output is correct
5 Correct 15 ms 9728 KB Output is correct
6 Correct 13 ms 9728 KB Output is correct
7 Incorrect 12 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 160 ms 26868 KB Output is correct
2 Correct 154 ms 27980 KB Output is correct
3 Correct 341 ms 30060 KB Output is correct
4 Correct 185 ms 29184 KB Output is correct
5 Correct 223 ms 26516 KB Output is correct
6 Correct 268 ms 29812 KB Output is correct
7 Correct 323 ms 28836 KB Output is correct
8 Correct 276 ms 29224 KB Output is correct
9 Correct 259 ms 27868 KB Output is correct
10 Correct 278 ms 27304 KB Output is correct
11 Correct 196 ms 23976 KB Output is correct
12 Correct 176 ms 23852 KB Output is correct
13 Correct 177 ms 23208 KB Output is correct
14 Correct 172 ms 22896 KB Output is correct
15 Correct 141 ms 20904 KB Output is correct
16 Correct 113 ms 20608 KB Output is correct
17 Correct 16 ms 11528 KB Output is correct
18 Correct 17 ms 11660 KB Output is correct
19 Correct 17 ms 11620 KB Output is correct
20 Correct 16 ms 11528 KB Output is correct
21 Correct 19 ms 11520 KB Output is correct
22 Correct 17 ms 11648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9984 KB Output is correct
2 Correct 13 ms 9984 KB Output is correct
3 Correct 15 ms 10112 KB Output is correct
4 Correct 14 ms 9984 KB Output is correct
5 Correct 13 ms 9984 KB Output is correct
6 Correct 15 ms 10004 KB Output is correct
7 Correct 15 ms 9984 KB Output is correct
8 Correct 14 ms 9984 KB Output is correct
9 Correct 11 ms 9984 KB Output is correct
10 Correct 11 ms 9984 KB Output is correct
11 Correct 14 ms 9984 KB Output is correct
12 Correct 14 ms 9984 KB Output is correct
13 Correct 12 ms 9984 KB Output is correct
14 Correct 11 ms 9984 KB Output is correct
15 Correct 11 ms 9948 KB Output is correct
16 Correct 12 ms 9856 KB Output is correct
17 Correct 12 ms 9984 KB Output is correct
18 Correct 12 ms 9984 KB Output is correct
19 Correct 11 ms 9984 KB Output is correct
20 Correct 14 ms 9984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 264 ms 29396 KB Output is correct
2 Correct 259 ms 29344 KB Output is correct
3 Correct 265 ms 29436 KB Output is correct
4 Correct 251 ms 29540 KB Output is correct
5 Correct 247 ms 29344 KB Output is correct
6 Correct 363 ms 35876 KB Output is correct
7 Correct 353 ms 33312 KB Output is correct
8 Correct 392 ms 32872 KB Output is correct
9 Correct 319 ms 31780 KB Output is correct
10 Correct 261 ms 29308 KB Output is correct
11 Correct 270 ms 29412 KB Output is correct
12 Correct 233 ms 29348 KB Output is correct
13 Correct 225 ms 29344 KB Output is correct
14 Correct 212 ms 28064 KB Output is correct
15 Correct 208 ms 26656 KB Output is correct
16 Correct 131 ms 21544 KB Output is correct
17 Correct 181 ms 28268 KB Output is correct
18 Correct 155 ms 28192 KB Output is correct
19 Correct 174 ms 28504 KB Output is correct
20 Correct 215 ms 28304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9984 KB Output is correct
2 Correct 14 ms 9984 KB Output is correct
3 Incorrect 14 ms 9948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 249 ms 29248 KB Output is correct
2 Correct 271 ms 29472 KB Output is correct
3 Incorrect 279 ms 27700 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 15 ms 9828 KB Output is correct
3 Correct 12 ms 9600 KB Output is correct
4 Correct 14 ms 9728 KB Output is correct
5 Correct 15 ms 9728 KB Output is correct
6 Correct 13 ms 9728 KB Output is correct
7 Incorrect 12 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 15 ms 9828 KB Output is correct
3 Correct 12 ms 9600 KB Output is correct
4 Correct 14 ms 9728 KB Output is correct
5 Correct 15 ms 9728 KB Output is correct
6 Correct 13 ms 9728 KB Output is correct
7 Incorrect 12 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -