#include <bits/stdc++.h>
#define N 100050
using namespace std;
typedef long long ll;
ll n, m, ok[N], ans, sz[N];
vector<int> grafo[N];
int tot;
void fill(int x, int p)
{
tot ++;
for(auto v: grafo[x])
{
if(v == p) continue;
fill(v, x);
}
}
void dfs(int x, int p)
{
sz[x] = ok[x] = 1;
ll quadrado = 0, soma = 0;
for(auto v: grafo[x])
{
if(v == p) continue;
dfs(v, x);
quadrado += sz[v] * sz[v];
soma += sz[v];
sz[x] += sz[v];
}
soma += tot - sz[x];
quadrado += (tot - sz[x]) * (tot - sz[x]);
ll prod2 = (soma * soma - quadrado);
ans += prod2;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
for(int i = 1, a, b; i <= m; i++)
{
cin>>a>>b;
grafo[a].push_back(b);
grafo[b].push_back(a);
}
for(int i = 1; i <= n; i++)
{
if(ok[i]) continue;
tot = 0;
fill(i, i);
dfs(i, i);
}
cout<<ans<<"\n";
//cout<<brute()<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1127 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1127 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1081 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 |
83 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 |
85 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 |
1127 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1127 ms |
1049600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |