#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll
const int N = 1e5 + 10;
vector<int> g[N];
bool used[N];
int sz[N], root[N], pr[N];
void dfs(int v, int rt) {
used[v] = true;
sz[v] = 1;
root[v] = rt;
for (auto u : g[v]) {
if (!used[u]) {
pr[u] = v;
dfs(u, rt);
sz[v] += sz[u];
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
for (int i = 1; i <= n; i++) {
if (!used[i]) {
dfs(i, i);
}
}
ll ans = 0;
for (int v = 1; v <= n; v++) {
for (auto u : g[v]) {
if (u == pr[v]) {
ans += (sz[root[v]] - sz[v]) * 1ll * (sz[v] - 1);
}
else {
ans += sz[u] * 1ll * (sz[root[v]] - sz[u] - 1);
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
14600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2816 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
2 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
2 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2816 KB |
Output is correct |
10 |
Correct |
3 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2816 KB |
Output is correct |
12 |
Correct |
2 ms |
2816 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2756 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
8440 KB |
Output is correct |
2 |
Correct |
55 ms |
8440 KB |
Output is correct |
3 |
Correct |
58 ms |
8488 KB |
Output is correct |
4 |
Correct |
54 ms |
8440 KB |
Output is correct |
5 |
Correct |
53 ms |
8440 KB |
Output is correct |
6 |
Correct |
66 ms |
11768 KB |
Output is correct |
7 |
Correct |
64 ms |
10616 KB |
Output is correct |
8 |
Correct |
61 ms |
9976 KB |
Output is correct |
9 |
Correct |
60 ms |
9464 KB |
Output is correct |
10 |
Correct |
54 ms |
8448 KB |
Output is correct |
11 |
Correct |
66 ms |
8444 KB |
Output is correct |
12 |
Correct |
56 ms |
8440 KB |
Output is correct |
13 |
Correct |
63 ms |
8440 KB |
Output is correct |
14 |
Correct |
51 ms |
8184 KB |
Output is correct |
15 |
Correct |
51 ms |
8056 KB |
Output is correct |
16 |
Correct |
29 ms |
6912 KB |
Output is correct |
17 |
Correct |
36 ms |
8696 KB |
Output is correct |
18 |
Correct |
37 ms |
8816 KB |
Output is correct |
19 |
Correct |
43 ms |
8684 KB |
Output is correct |
20 |
Correct |
42 ms |
8704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2816 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Incorrect |
3 ms |
2816 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
8440 KB |
Output is correct |
2 |
Correct |
64 ms |
8444 KB |
Output is correct |
3 |
Incorrect |
95 ms |
8568 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |