Submission #753030

# Submission time Handle Problem Language Result Execution time Memory
753030 2023-06-04T13:33:01 Z wmrmr Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
#define all(v) v.begin(), v.end()
#define pb push_back

void dbg_out() { cerr << endl; }
template<typename H, typename... T> 
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

constexpr int N = 100'000;
vector<int> g[N];

int n, m;
int ans = 0;
int sub[N];

void dfs(int u, int dad=-1) {
	sub[u] = 1;
	for(int v: g[u]) if(v != dad) {
		dfs(v, u);
		sub[u] += sub[v];
	}
	int cnt = 0;
	for(int v: g[u]) if(v != dad) {
		cnt += sub[v] * (n - sub[v] - 1);
	}
	cnt += (n - sub[u]) * (sub[u] - 1);
	ans += cnt;
}

void solve() {
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int u, v; cin >> u >> v;
		--u; --v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(0);
	cout << ans << '\n';
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	solve();
}
# Verdict Execution time Memory Grader output
1 Runtime error 627 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 627 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 449824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2684 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2716 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Incorrect 3 ms 2644 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 8432 KB Output is correct
2 Correct 77 ms 8432 KB Output is correct
3 Correct 41 ms 8304 KB Output is correct
4 Correct 62 ms 8316 KB Output is correct
5 Correct 60 ms 8400 KB Output is correct
6 Correct 69 ms 12016 KB Output is correct
7 Correct 68 ms 11128 KB Output is correct
8 Correct 65 ms 10452 KB Output is correct
9 Correct 63 ms 9728 KB Output is correct
10 Incorrect 53 ms 8396 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Runtime error 570 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 8396 KB Output is correct
2 Correct 46 ms 8304 KB Output is correct
3 Runtime error 675 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 627 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 627 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -