#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b){a = b; return true;}
return false;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b){a = b; return true;}
return false;
}
template <class T>
void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
for(auto i: a) out << i << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 1e5 + 69;
int n, m;
vector<int> graph[N];
int sz[N];
ll ans = 0;
void dfs(int u,int p){
sz[u] = 1;
for(int v: graph[u]) if (v != p){
dfs(v, u);
sz[u] += sz[v];
}
}
void go(int u,int p, int L){
for(int v: graph[u]) if (v != p){
go(v, u, L);
ans += 1LL * sz[v] * (L - sz[v]);
}
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
// if (m != n - 1) return -1;
for(int i= 0; i<m; ++i){
int u, v; cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
for(int i= 1; i<=n; ++i) if (sz[i] == 0){
dfs(i, i);
go(i, i, sz[i]);
ans -= 1LL * sz[i] * (sz[i] - 1) / 2;
}
ans *= 2;
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
759 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
759 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
928600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
1 ms |
3076 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2904 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2904 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
3068 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
3068 KB |
Output is correct |
13 |
Correct |
1 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
2908 KB |
Output is correct |
15 |
Correct |
1 ms |
2904 KB |
Output is correct |
16 |
Correct |
1 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
3040 KB |
Output is correct |
18 |
Correct |
1 ms |
3160 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
7520 KB |
Output is correct |
2 |
Correct |
28 ms |
7516 KB |
Output is correct |
3 |
Correct |
29 ms |
7696 KB |
Output is correct |
4 |
Correct |
28 ms |
7460 KB |
Output is correct |
5 |
Correct |
28 ms |
7516 KB |
Output is correct |
6 |
Correct |
34 ms |
11604 KB |
Output is correct |
7 |
Correct |
35 ms |
10320 KB |
Output is correct |
8 |
Correct |
48 ms |
9672 KB |
Output is correct |
9 |
Correct |
36 ms |
8784 KB |
Output is correct |
10 |
Correct |
35 ms |
7680 KB |
Output is correct |
11 |
Correct |
29 ms |
7504 KB |
Output is correct |
12 |
Correct |
28 ms |
7472 KB |
Output is correct |
13 |
Correct |
38 ms |
7672 KB |
Output is correct |
14 |
Correct |
24 ms |
7248 KB |
Output is correct |
15 |
Correct |
22 ms |
7004 KB |
Output is correct |
16 |
Correct |
14 ms |
5980 KB |
Output is correct |
17 |
Correct |
20 ms |
7892 KB |
Output is correct |
18 |
Correct |
21 ms |
7788 KB |
Output is correct |
19 |
Correct |
22 ms |
7888 KB |
Output is correct |
20 |
Correct |
21 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
1 ms |
2904 KB |
Output is correct |
3 |
Runtime error |
588 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
7504 KB |
Output is correct |
2 |
Correct |
30 ms |
7764 KB |
Output is correct |
3 |
Runtime error |
652 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
759 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
759 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |