Submission #829769

# Submission time Handle Problem Language Result Execution time Memory
829769 2023-08-18T14:52:27 Z caganyanmaz Duathlon (APIO18_duathlon) C++14
23 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
using namespace std;

constexpr static int MXN = 1e5;
int n, m;
vector<int> g[MXN];
bitset<MXN> visited;
int subtree_size[MXN];

int res;
void dfs1(int node, int p)
{
	visited[node] = true;
	subtree_size[node] = 1;
	for (int c : g[node])
	{
		if (c == p)
			continue;
		dfs1(c, node);
		subtree_size[node] += subtree_size[c];
	}

}

void dfs2(int node, int p, int sum)
{
	for (int c : g[node])
	{
		if (c == p)
			continue;
		dfs2(c, node, sum);
		res += subtree_size[c] * (sum - subtree_size[c] - 1);
	}
	int rem = sum - subtree_size[node];
	res += (subtree_size[node] - 1) * rem;
}

int32_t main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--,b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	for (int i = 0; i < n; i++)
	{
		if (!visited[i])
		{
			dfs1(i, i);
			dfs2(i, i, subtree_size[i]);
		}
	}
	cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Runtime error 404 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 404 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1101 ms 955244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2672 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 7624 KB Output is correct
2 Correct 63 ms 7200 KB Output is correct
3 Correct 63 ms 7220 KB Output is correct
4 Correct 78 ms 7332 KB Output is correct
5 Correct 95 ms 7240 KB Output is correct
6 Correct 76 ms 10884 KB Output is correct
7 Correct 75 ms 10052 KB Output is correct
8 Correct 79 ms 9268 KB Output is correct
9 Correct 65 ms 8552 KB Output is correct
10 Correct 87 ms 7200 KB Output is correct
11 Correct 72 ms 7672 KB Output is correct
12 Correct 69 ms 7648 KB Output is correct
13 Correct 74 ms 7660 KB Output is correct
14 Correct 55 ms 7444 KB Output is correct
15 Correct 53 ms 7120 KB Output is correct
16 Correct 33 ms 6308 KB Output is correct
17 Correct 55 ms 7860 KB Output is correct
18 Correct 54 ms 7740 KB Output is correct
19 Correct 53 ms 7760 KB Output is correct
20 Correct 53 ms 7832 KB Output is correct
# 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 451 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7184 KB Output is correct
2 Correct 63 ms 7172 KB Output is correct
3 Runtime error 535 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 404 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 404 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -