#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
#define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 1003;
int n, m, root, used[n0], anc[n0], sz[n0], back;
vector <int> g[n0];
void dfs(int v, int p) {
used[v] = 1;
if (v != root) {
if (p == root)
anc[v] = v;
else
anc[v] = anc[p];
sz[anc[v]]++;
}
for (int to : g[v]) {
if (to == p) continue;
if (used[to] == 1 && to == root) {
sz[anc[v]]--;
back++;
}
if (!used[to])
dfs(to, v);
}
used[v] = 2;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
g[x].pb(y), g[y].pb(x);
}
ll res = 0;
for (int i = 1; i <= n; i++) {
root = i;
memset(& used, 0, sizeof(used));
memset(& anc, 0, sizeof(anc));
memset(& sz, 0, sizeof(sz));
back = 0;
dfs(i, -1);
for (int j = 1; j <= n; j++)
res += sz[j] * (n - 1 - sz[j]);
res += back * (n - 2);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Correct |
19 ms |
512 KB |
Output is correct |
4 |
Correct |
22 ms |
512 KB |
Output is correct |
5 |
Correct |
20 ms |
384 KB |
Output is correct |
6 |
Correct |
23 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
512 KB |
Output is correct |
8 |
Correct |
19 ms |
384 KB |
Output is correct |
9 |
Correct |
19 ms |
384 KB |
Output is correct |
10 |
Incorrect |
16 ms |
512 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Output is correct |
2 |
Correct |
17 ms |
384 KB |
Output is correct |
3 |
Incorrect |
19 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
560 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |