Submission #405390

# Submission time Handle Problem Language Result Execution time Memory
405390 2021-05-16T10:33:32 Z aryan12 Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1048580 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5;
vector<int> g[N];
int subtree[N], ans = 0;
int n, m;

void dfs(int node, int par) {
	subtree[node] = 1;
	for(int i = 0; i < g[node].size(); i++) {
		if(g[node][i] != par) {
			dfs(g[node][i], node);
			subtree[node] += subtree[g[node][i]];
		}
	}
	//cout << "node = " << node << ", subtree[node] = " << subtree[node] << "\n";
	int total = subtree[node] - 1, left = n - 1;
	for(int i = 0; i < g[node].size(); i++) {
		if(g[node][i] != par) {
			left -= subtree[g[node][i]];
			ans += (subtree[g[node][i]] * left);
		}
	}
	//cout << "node = " << node << ", ans = " << ans << "\n";
}

void Solve() {
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int v, u;
		cin >> v >> u;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(1, -1);
	cout << ans * 2 << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
}

/*
8 7
1 2
2 3
3 4
2 5
5 8
1 6
6 7

*/

Compilation message

count_triplets.cpp: In function 'void dfs(long long int, long long int)':
count_triplets.cpp:14:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i < g[node].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~
count_triplets.cpp:22:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = 0; i < g[node].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~
count_triplets.cpp:21:6: warning: unused variable 'total' [-Wunused-variable]
   21 |  int total = subtree[node] - 1, left = n - 1;
      |      ^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 668 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 668 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 295520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 3 ms 2684 KB Output is correct
3 Correct 3 ms 2636 KB Output is correct
4 Correct 3 ms 2680 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2680 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 3 ms 2676 KB Output is correct
10 Incorrect 3 ms 2636 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7444 KB Output is correct
2 Correct 56 ms 8340 KB Output is correct
3 Correct 60 ms 8324 KB Output is correct
4 Correct 69 ms 8328 KB Output is correct
5 Correct 59 ms 8424 KB Output is correct
6 Correct 57 ms 10308 KB Output is correct
7 Correct 66 ms 10012 KB Output is correct
8 Correct 63 ms 9704 KB Output is correct
9 Correct 60 ms 9156 KB Output is correct
10 Incorrect 64 ms 8388 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Runtime error 765 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 7460 KB Output is correct
2 Correct 68 ms 8220 KB Output is correct
3 Runtime error 960 ms 1048580 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 668 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 668 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -