#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];
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 += n - sz[x];
quadrado += (n - sz[x]) * (n - 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;
dfs(i, i);
}
cout<<ans<<"\n";
//cout<<brute()<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1120 ms |
792800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1120 ms |
792800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1099 ms |
792800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
792800 KB |
Output is correct |
2 |
Correct |
5 ms |
792800 KB |
Output is correct |
3 |
Correct |
6 ms |
792800 KB |
Output is correct |
4 |
Correct |
6 ms |
792800 KB |
Output is correct |
5 |
Correct |
6 ms |
792800 KB |
Output is correct |
6 |
Correct |
5 ms |
792800 KB |
Output is correct |
7 |
Correct |
5 ms |
792800 KB |
Output is correct |
8 |
Correct |
5 ms |
792800 KB |
Output is correct |
9 |
Correct |
5 ms |
792800 KB |
Output is correct |
10 |
Incorrect |
5 ms |
792800 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
792800 KB |
Output is correct |
2 |
Correct |
97 ms |
792800 KB |
Output is correct |
3 |
Correct |
90 ms |
792800 KB |
Output is correct |
4 |
Correct |
121 ms |
792800 KB |
Output is correct |
5 |
Correct |
115 ms |
792800 KB |
Output is correct |
6 |
Correct |
145 ms |
792800 KB |
Output is correct |
7 |
Correct |
152 ms |
792800 KB |
Output is correct |
8 |
Correct |
122 ms |
792800 KB |
Output is correct |
9 |
Correct |
115 ms |
792800 KB |
Output is correct |
10 |
Incorrect |
103 ms |
792800 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
792800 KB |
Output is correct |
2 |
Correct |
7 ms |
792800 KB |
Output is correct |
3 |
Execution timed out |
1153 ms |
979212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
979212 KB |
Output is correct |
2 |
Correct |
126 ms |
979212 KB |
Output is correct |
3 |
Execution timed out |
1188 ms |
979212 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1120 ms |
792800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1120 ms |
792800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |