Submission #59303

# Submission time Handle Problem Language Result Execution time Memory
59303 2018-07-21T13:00:57 Z thiago4532 Duathlon (APIO18_duathlon) C++17
0 / 100
1000 ms 1049600 KB
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 10, inf = 0x3f3f3f3f;
vector<int> grafo[maxn];
int sz[maxn];
int mark[maxn], root[maxn];

void dfs(int u, int p=0){
	sz[u] = 1;
	for(auto v : grafo[u]){
		if(v == p) continue;

		mark[v] = mark[u];	
		dfs(v, u);
		sz[u] += sz[v];
	}
}

int ans;
void solve(int u, int p=0, int acc=0){
	ans += (2 * acc * (sz[u] - 1));

	for(auto v : grafo[u]){
		if(v == p) continue;
		ans += (sz[u] - sz[v] - 1) * sz[v];
		solve(v, u, sz[u] - sz[v] + acc);
	}
}

int main(){
	int n, m;
	cin >> n >> m;
	for(int i=1;i<=m;i++){
		int a, b;
		cin >> a >> b;
		grafo[a].push_back(b);
		grafo[b].push_back(a);
	}

	int cnt=0;
	for(int i=1;i<=n;i++)
		if(!mark[i]) mark[i] = ++cnt, root[cnt] = i, dfs(i);

	for(int i=1;i<=cnt;i++)
		solve(root[i]);

	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1144 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1144 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1049600 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 214 ms 1049600 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 1049600 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 189 ms 1049600 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1144 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1144 ms 1049600 KB Time limit exceeded
2 Halted 0 ms 0 KB -