Submission #159649

# Submission time Handle Problem Language Result Execution time Memory
159649 2019-10-23T17:34:45 Z Minnakhmetov Duathlon (APIO18_duathlon) C++14
10 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
  
using namespace std;

const int N = 1e5 + 5;
vector<int> g[N], g2[N], v;
int tin[N], mnt[N], sz[N];
bool used[N];
int timer = 0, cnt = 0, cv = 0;
int n, m;
ll ans = 0;

void dfs(int node, int anc) {
    mnt[node] = tin[node] = ++timer;
    used[node] = 1;

    cnt++;
    v.push_back(node);

    for (int to : g[node]) {
        if (to != anc) {
            if (!used[to]) {
                dfs(to, node);
                mnt[node] = min(mnt[node], mnt[to]);

                if (mnt[to] >= tin[node]) {
                    g2[node].push_back(cv);

                    while (v.back() != node) {
                        g2[cv].push_back(v.back());
                        v.pop_back();
                    }
                    cv++;
                }
            }
            else {
                mnt[node] = min(mnt[node], tin[to]);
            }
        }
    }
}

void dive(int node) {
    sz[node] = (node < n);
    for (int to : g2[node]) {
        dive(to);
        sz[node] += sz[to];

        if (node >= n)
            ans -= sz[to] * (ll)(sz[to] - 1) * (ll)g2[node].size();
    }

    if (node >= n) {
        ans -= (cnt - sz[node]) * (ll)(cnt - sz[node] - 1) * (ll)g2[node].size();
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n >> m;
 
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    cv = n;

    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            cnt = 0;
            dfs(i, -1);
            ans += cnt * (ll)(cnt - 1) * (cnt - 2);
            dive(i);
        }
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 17904 KB Output is correct
2 Correct 67 ms 17900 KB Output is correct
3 Execution timed out 1057 ms 14464 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 7 ms 5136 KB Output is correct
3 Correct 6 ms 5240 KB Output is correct
4 Correct 7 ms 5240 KB Output is correct
5 Correct 7 ms 5240 KB Output is correct
6 Correct 7 ms 5240 KB Output is correct
7 Correct 7 ms 5240 KB Output is correct
8 Correct 7 ms 5240 KB Output is correct
9 Correct 7 ms 5240 KB Output is correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 7 ms 5240 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 7 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 7 ms 5116 KB Output is correct
20 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 1048580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Incorrect 6 ms 5112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 980 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -