Submission #260907

# Submission time Handle Problem Language Result Execution time Memory
260907 2020-08-11T07:31:07 Z SorahISA Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1048580 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false), cin.tie(0)

const int maxn = 1E5 + 5;

int ans = 0;
vector<int> adj[maxn], vis(maxn), sz(maxn, 1);

void dfs(int now, int lst) {
    vis[now] = 1;
    for (auto x : adj[now]) {
        if (x != lst) dfs(x, now), sz[now] += sz[x];
    }
}

void dfs2(int now, int lst, int rt) {
    for (auto x : adj[now]) {
        if (x == lst) continue;
        ans += 2 * sz[x] * (sz[rt] - sz[x] - 1);
        // cout << now << " : " << 2 * sz[x] * (sz[rt] - sz[x] - 1) << "\n";
        dfs2(x, now, rt);
    }
}

int32_t main() {
    fastIO();
    
    int n, m;
    cin >> n >> m;
    
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].eb(v), adj[v].eb(u);
    }
    
    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            dfs(i, -1), dfs2(i, -1, i);
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 604 ms 1048580 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 Runtime error 604 ms 1048580 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 Execution timed out 1091 ms 298552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 8044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 8060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 604 ms 1048580 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 Runtime error 604 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -