#include <bits/stdc++.h>
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define M ll(998244353)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
vector <int> g[N];
bool mk[N], mkr[N];
int ans, i, j, n, m;
ll anser, siz[N];
void dfs(int v, int p)
{
siz[v] = 0;
for (auto it : g[v])
{
if (it == p) continue;
dfs(it, v);
siz[v] += siz[it];
}
if (v == i) for (auto it : g[v]) {if (it == p) continue; siz[v] -= siz[it]; anser += siz[v] * siz[it];}
siz[v]++;
}
bool dostig(int v, int to)
{
if (mk[v]) return 0;
if (v == to) return 1;
mk[v] = 1;
bool f = 0;
for (auto it : g[v]) f |= dostig(it, to);
mk[v] = 0;
if (f && v != i && !mkr[v]) {mkr[v] = 1; ans++;}
return f;
}
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
if (m <= n - 1)
{
for (i = 1; i <= n; i++) dfs(i, -1);
cout << anser * 2<< endl;
exit(0);
}
ans = 0;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
if (i != j){for (int u = 0; u < 51; u++) mkr[u] = 0; dostig(i, j);}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
539 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Runtime error |
561 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
539 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Runtime error |
561 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1099 ms |
13432 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2688 KB |
Output is correct |
2 |
Correct |
21 ms |
2816 KB |
Output is correct |
3 |
Correct |
21 ms |
2688 KB |
Output is correct |
4 |
Correct |
26 ms |
2816 KB |
Output is correct |
5 |
Correct |
28 ms |
2816 KB |
Output is correct |
6 |
Correct |
24 ms |
2816 KB |
Output is correct |
7 |
Correct |
26 ms |
2816 KB |
Output is correct |
8 |
Correct |
24 ms |
2816 KB |
Output is correct |
9 |
Correct |
23 ms |
2816 KB |
Output is correct |
10 |
Correct |
19 ms |
2688 KB |
Output is correct |
11 |
Correct |
17 ms |
2688 KB |
Output is correct |
12 |
Correct |
11 ms |
2688 KB |
Output is correct |
13 |
Correct |
8 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
14 ms |
2688 KB |
Output is correct |
18 |
Correct |
15 ms |
2688 KB |
Output is correct |
19 |
Correct |
14 ms |
2816 KB |
Output is correct |
20 |
Correct |
15 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
7928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2688 KB |
Output is correct |
2 |
Correct |
21 ms |
2688 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
2688 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
7928 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
539 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Runtime error |
561 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
6 ms |
2688 KB |
Output is correct |
7 |
Correct |
6 ms |
2688 KB |
Output is correct |
8 |
Correct |
6 ms |
2688 KB |
Output is correct |
9 |
Correct |
27 ms |
2688 KB |
Output is correct |
10 |
Correct |
539 ms |
2808 KB |
Output is correct |
11 |
Correct |
6 ms |
2688 KB |
Output is correct |
12 |
Correct |
6 ms |
2688 KB |
Output is correct |
13 |
Correct |
6 ms |
2688 KB |
Output is correct |
14 |
Correct |
6 ms |
2688 KB |
Output is correct |
15 |
Correct |
6 ms |
2688 KB |
Output is correct |
16 |
Correct |
6 ms |
2688 KB |
Output is correct |
17 |
Correct |
6 ms |
2688 KB |
Output is correct |
18 |
Correct |
6 ms |
2688 KB |
Output is correct |
19 |
Correct |
6 ms |
2688 KB |
Output is correct |
20 |
Runtime error |
561 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
21 |
Halted |
0 ms |
0 KB |
- |