Submission #216356

# Submission time Handle Problem Language Result Execution time Memory
216356 2020-03-27T08:01:25 Z theStaticMind Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1048580 KB
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

vector<int> adj[300005];
vector<int> sub(300005, 1);
int ans = 0;

void dfs(int x, int pre){
	sub[x] = 1;
	for(auto y : adj[x]){
		if(y == pre) continue;
		dfs(y, x);
		sub[x] += sub[y];
	}
}

void calc(int x, int pre){
	ans += 2ll * (sub[x] - 1) * (sub[1] - sub[x]);

	int w = 0;

	for(auto y : adj[x]){
		if(y == pre) continue;
		ans += 2ll * sub[y] * w;
		w += sub[y];
	}

	for(auto y : adj[x]){
		if(y == pre) continue;
		calc(y, x);
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;

	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	dfs(1, -1);

	calc(1, -1);

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 545 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 545 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 1099 ms 453984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 10 ms 9856 KB Output is correct
3 Correct 11 ms 9856 KB Output is correct
4 Correct 10 ms 9856 KB Output is correct
5 Correct 12 ms 9856 KB Output is correct
6 Correct 10 ms 9856 KB Output is correct
7 Correct 11 ms 9856 KB Output is correct
8 Correct 10 ms 9856 KB Output is correct
9 Correct 10 ms 9728 KB Output is correct
10 Incorrect 10 ms 9856 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 14712 KB Output is correct
2 Correct 71 ms 14712 KB Output is correct
3 Correct 72 ms 14712 KB Output is correct
4 Correct 67 ms 14712 KB Output is correct
5 Correct 64 ms 14712 KB Output is correct
6 Correct 83 ms 17528 KB Output is correct
7 Correct 84 ms 17016 KB Output is correct
8 Correct 90 ms 16376 KB Output is correct
9 Correct 71 ms 15736 KB Output is correct
10 Incorrect 62 ms 14712 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9984 KB Output is correct
2 Correct 11 ms 9728 KB Output is correct
3 Runtime error 689 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 14712 KB Output is correct
2 Correct 69 ms 14584 KB Output is correct
3 Runtime error 829 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 545 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 545 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -