#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1144 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1144 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
208 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
161 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1144 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1144 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |