Submission #64924

# Submission time Handle Problem Language Result Execution time Memory
64924 2018-08-06T06:39:08 Z gusfring Duathlon (APIO18_duathlon) C++14
23 / 100
1000 ms 865736 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;
typedef long long ll;
int sz[MAXN], N, M, vis[MAXN], S;
ll res;
vector<int> adj[MAXN];

void dfs(int u, int p){
	vis[u] = 1, sz[u] = 1;
	for(int v : adj[u])
		if(v != p){ dfs(v, u); sz[u] += sz[v]; }
}

void solve(int u, int p){
	vector<int> vec;
	if(p != -1) vec.push_back(S - sz[u]);
	for(int v : adj[u])
		if(v != p){
			vec.push_back(sz[v]);
			solve(v, u);
		}
	int sum = 0;
	for(int x : vec){
		res += 1LL * sum * x;
		sum += x;
	}
}

int main(){
	scanf("%d %d", &N, &M);
	while(M--){
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i=1; i<=N; ++i)
		if(!vis[i]){
			dfs(i, -1);
			S = sz[i];
			solve(i, -1);
		}
	printf("%lld\n", 2 * res);
	return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1132 ms 799376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1132 ms 799376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 799376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 799376 KB Output is correct
2 Correct 7 ms 799376 KB Output is correct
3 Correct 9 ms 799376 KB Output is correct
4 Correct 6 ms 799376 KB Output is correct
5 Correct 7 ms 799376 KB Output is correct
6 Correct 8 ms 799376 KB Output is correct
7 Correct 9 ms 799376 KB Output is correct
8 Correct 8 ms 799376 KB Output is correct
9 Correct 7 ms 799376 KB Output is correct
10 Correct 7 ms 799376 KB Output is correct
11 Correct 6 ms 799376 KB Output is correct
12 Correct 6 ms 799376 KB Output is correct
13 Correct 7 ms 799376 KB Output is correct
14 Correct 6 ms 799376 KB Output is correct
15 Correct 7 ms 799376 KB Output is correct
16 Correct 6 ms 799376 KB Output is correct
17 Correct 7 ms 799376 KB Output is correct
18 Correct 11 ms 799376 KB Output is correct
19 Correct 8 ms 799376 KB Output is correct
20 Correct 11 ms 799376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 799376 KB Output is correct
2 Correct 176 ms 799376 KB Output is correct
3 Correct 250 ms 799376 KB Output is correct
4 Correct 189 ms 799376 KB Output is correct
5 Correct 182 ms 799376 KB Output is correct
6 Correct 211 ms 799376 KB Output is correct
7 Correct 209 ms 799376 KB Output is correct
8 Correct 194 ms 799376 KB Output is correct
9 Correct 207 ms 799376 KB Output is correct
10 Correct 214 ms 799376 KB Output is correct
11 Correct 203 ms 799376 KB Output is correct
12 Correct 179 ms 799376 KB Output is correct
13 Correct 190 ms 799376 KB Output is correct
14 Correct 127 ms 799376 KB Output is correct
15 Correct 109 ms 799376 KB Output is correct
16 Correct 83 ms 799376 KB Output is correct
17 Correct 119 ms 799376 KB Output is correct
18 Correct 171 ms 799376 KB Output is correct
19 Correct 126 ms 799376 KB Output is correct
20 Correct 118 ms 799376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 799376 KB Output is correct
2 Correct 6 ms 799376 KB Output is correct
3 Execution timed out 1193 ms 865736 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 172 ms 865736 KB Output is correct
2 Correct 164 ms 865736 KB Output is correct
3 Execution timed out 1079 ms 865736 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1132 ms 799376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1132 ms 799376 KB Time limit exceeded
2 Halted 0 ms 0 KB -