#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 1e6 + 10;
int n, m, H[MAXN], tin[MAXN], low[MAXN], t, cnt, sz[MAXN];
stack<int> st;
vector<int> adj[MAXN], G[MAXN];
bool vis[MAXN];
ll ans = 0;
void dfs(int v, int p) {
st.push(v);
tin[v] = low[v] = t++;
for (int u : adj[v]) {
if (u == p) continue;
if (tin[u]) low[v] = min(low[v], tin[u]);
else {
dfs(u, v);
low[v] = min(low[v], low[u]);
if (low[u] >= tin[v]) {
cnt++;
G[v].push_back(n + cnt);
while (G[n + cnt].empty() || G[n + cnt].back() != u) {
G[n + cnt].push_back(st.top());
st.pop();
}
}
}
}
}
void solve(int v) {
if (v <= n) sz[v] = 1;
for (int u : G[v]) {
solve(u);
sz[v] += sz[u];
if (v > n) ans -= 1ll * sz[u] * (sz[u] - 1) * G[v].size();
}
if (v > n) ans -= 1ll * (n - sz[v]) * (n - sz[v] - 1) * G[v].size();
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
if (tin[i]) continue;
t = 0;
dfs(i, 0);
ans += 1ll * t * (t - 1) * (t - 2);
solve(i);
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
113 ms |
64452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
47412 KB |
Output is correct |
2 |
Correct |
29 ms |
47328 KB |
Output is correct |
3 |
Correct |
29 ms |
47308 KB |
Output is correct |
4 |
Correct |
28 ms |
47456 KB |
Output is correct |
5 |
Correct |
24 ms |
47444 KB |
Output is correct |
6 |
Correct |
26 ms |
47444 KB |
Output is correct |
7 |
Correct |
26 ms |
47448 KB |
Output is correct |
8 |
Correct |
22 ms |
47444 KB |
Output is correct |
9 |
Correct |
28 ms |
47360 KB |
Output is correct |
10 |
Incorrect |
25 ms |
47416 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
58088 KB |
Output is correct |
2 |
Correct |
101 ms |
58060 KB |
Output is correct |
3 |
Correct |
136 ms |
58028 KB |
Output is correct |
4 |
Correct |
163 ms |
58116 KB |
Output is correct |
5 |
Correct |
117 ms |
58136 KB |
Output is correct |
6 |
Correct |
132 ms |
68020 KB |
Output is correct |
7 |
Correct |
128 ms |
64332 KB |
Output is correct |
8 |
Correct |
107 ms |
62824 KB |
Output is correct |
9 |
Correct |
107 ms |
61284 KB |
Output is correct |
10 |
Incorrect |
94 ms |
58112 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
47316 KB |
Output is correct |
2 |
Correct |
28 ms |
47352 KB |
Output is correct |
3 |
Correct |
30 ms |
47316 KB |
Output is correct |
4 |
Incorrect |
25 ms |
47300 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
58100 KB |
Output is correct |
2 |
Correct |
108 ms |
58384 KB |
Output is correct |
3 |
Correct |
102 ms |
57820 KB |
Output is correct |
4 |
Incorrect |
109 ms |
55988 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
47312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |