Submission #927766

# Submission time Handle Problem Language Result Execution time Memory
927766 2024-02-15T10:09:00 Z TAhmed33 Duathlon (APIO18_duathlon) C++
0 / 100
79 ms 16564 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
vector <int> adj[300001];
int sze[300001];
bool vis[300001];
void calc (int pos, int par) {
  	vis[pos] = 1;
	for (auto j : adj[pos]) {
		if (j == par) continue;
		calc(j, pos);
		sze[pos] += sze[j];
	}
	sze[pos]++;
}
int ans = 0;
void dfs (int pos, int par) {
  	vis[pos] = 1;
    ans += 2 * (n - sze[pos]) * (sze[pos] - 1);
    int cur = 0;
    for (auto j : adj[pos]) {
        if (j == par) continue;
        ans += 2 * sze[j] * cur;
        cur += sze[j];
        dfs(j, pos);
    }
}
signed main () {
    cin >> n; int m; cin >> m; assert(m == n - 1);
    for (int i = 1; i <= m; i++) {
	    int a, b;
	    cin >> a >> b;
	    adj[a].push_back(b);
	    adj[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) if (!vis[i]) calc(i, -1);
    memset(vis, 0, sizeof(vis));
  	for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i, -1);
  	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 15704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 15704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 15704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10076 KB Output is correct
2 Correct 3 ms 10072 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 2 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 10076 KB Output is correct
8 Correct 3 ms 10076 KB Output is correct
9 Correct 3 ms 10076 KB Output is correct
10 Runtime error 8 ms 15708 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 61 ms 13652 KB Output is correct
2 Correct 56 ms 13652 KB Output is correct
3 Correct 55 ms 13652 KB Output is correct
4 Correct 55 ms 13824 KB Output is correct
5 Correct 79 ms 13908 KB Output is correct
6 Correct 62 ms 16564 KB Output is correct
7 Correct 59 ms 15956 KB Output is correct
8 Correct 61 ms 15188 KB Output is correct
9 Correct 58 ms 14672 KB Output is correct
10 Runtime error 8 ms 15704 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10076 KB Output is correct
2 Correct 4 ms 10076 KB Output is correct
3 Runtime error 8 ms 15708 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 13652 KB Output is correct
2 Correct 59 ms 13648 KB Output is correct
3 Runtime error 8 ms 15704 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 15704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 15704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -