// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 3e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;
vector<int> v[maxn], g[maxn], vec;
int up[maxn], h[maxn], val[maxn], n;
bool mark[maxn];
int C;
void add_edge(int a, int b){
g[a].PB(b);
g[b].PB(a);
}
void prep(int u){
n++;
mark[u] = 1;
up[u] = h[u];
for(int y : v[u]){
if(!mark[y]){
int SZ = sz(vec);
h[y] = h[u] + 1;
prep(y);
up[u] = min(up[u], up[y]);
if(up[y] == h[u]){
while(sz(vec) > SZ){
add_edge(vec.back(), C);
vec.pop_back();
}
add_edge(u, C);
val[C] = sz(g[C]) - 1;
C++;
}
}
else{
up[u] = min(up[u], h[y]);
}
}
vec.PB(u);
}
ll ans;
int SZ[maxn];
void dfs(int u, int par = -1){
SZ[u] = (u < n);
ll num = 0;
for(int y : g[u])
if(y != par)
dfs(y, u), SZ[u]+= SZ[y], num+= 1ll * SZ[y] * (SZ[y]-1);
num+= 1ll * (n-SZ[u]) * (n-SZ[u]-1);
ans+= 1ll * val[u] * (1ll * n * (n-1) - num);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int N, m;
cin >> N >> m;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
--a, --b;
v[a].PB(b);
v[b].PB(a);
}
C = N;
for(int i = 0; i < N; i++){
if(!mark[i]){
assert(i == 0);
n = 0;
prep(i);
ans = -1ll * n * (n-1);
dfs(i);
}
}
return cout << ans << endl, 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
29048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
29048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
32112 KB |
Output is correct |
2 |
Correct |
81 ms |
32212 KB |
Output is correct |
3 |
Runtime error |
120 ms |
51504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14592 KB |
Output is correct |
2 |
Correct |
12 ms |
14592 KB |
Output is correct |
3 |
Correct |
9 ms |
14592 KB |
Output is correct |
4 |
Correct |
12 ms |
14720 KB |
Output is correct |
5 |
Correct |
8 ms |
14592 KB |
Output is correct |
6 |
Correct |
9 ms |
14592 KB |
Output is correct |
7 |
Correct |
9 ms |
14592 KB |
Output is correct |
8 |
Correct |
12 ms |
14592 KB |
Output is correct |
9 |
Correct |
9 ms |
14592 KB |
Output is correct |
10 |
Runtime error |
22 ms |
29184 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
26104 KB |
Output is correct |
2 |
Correct |
102 ms |
26104 KB |
Output is correct |
3 |
Correct |
110 ms |
26104 KB |
Output is correct |
4 |
Correct |
98 ms |
26104 KB |
Output is correct |
5 |
Correct |
98 ms |
26104 KB |
Output is correct |
6 |
Correct |
109 ms |
34424 KB |
Output is correct |
7 |
Correct |
116 ms |
31608 KB |
Output is correct |
8 |
Correct |
113 ms |
30200 KB |
Output is correct |
9 |
Correct |
107 ms |
28792 KB |
Output is correct |
10 |
Runtime error |
94 ms |
46508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14592 KB |
Output is correct |
2 |
Correct |
10 ms |
14592 KB |
Output is correct |
3 |
Correct |
8 ms |
14592 KB |
Output is correct |
4 |
Correct |
8 ms |
14592 KB |
Output is correct |
5 |
Correct |
8 ms |
14592 KB |
Output is correct |
6 |
Correct |
8 ms |
14592 KB |
Output is correct |
7 |
Correct |
8 ms |
14592 KB |
Output is correct |
8 |
Correct |
9 ms |
14592 KB |
Output is correct |
9 |
Correct |
11 ms |
14592 KB |
Output is correct |
10 |
Correct |
10 ms |
14592 KB |
Output is correct |
11 |
Correct |
10 ms |
14592 KB |
Output is correct |
12 |
Correct |
8 ms |
14592 KB |
Output is correct |
13 |
Correct |
10 ms |
14592 KB |
Output is correct |
14 |
Correct |
8 ms |
14592 KB |
Output is correct |
15 |
Correct |
9 ms |
14592 KB |
Output is correct |
16 |
Runtime error |
23 ms |
29184 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
26104 KB |
Output is correct |
2 |
Correct |
101 ms |
25976 KB |
Output is correct |
3 |
Correct |
117 ms |
25464 KB |
Output is correct |
4 |
Correct |
107 ms |
24440 KB |
Output is correct |
5 |
Correct |
97 ms |
23672 KB |
Output is correct |
6 |
Correct |
92 ms |
23292 KB |
Output is correct |
7 |
Correct |
91 ms |
23160 KB |
Output is correct |
8 |
Correct |
114 ms |
22904 KB |
Output is correct |
9 |
Correct |
88 ms |
22904 KB |
Output is correct |
10 |
Correct |
87 ms |
22776 KB |
Output is correct |
11 |
Correct |
112 ms |
22904 KB |
Output is correct |
12 |
Correct |
91 ms |
22904 KB |
Output is correct |
13 |
Correct |
94 ms |
22904 KB |
Output is correct |
14 |
Correct |
119 ms |
25080 KB |
Output is correct |
15 |
Correct |
184 ms |
31224 KB |
Output is correct |
16 |
Correct |
173 ms |
29176 KB |
Output is correct |
17 |
Correct |
113 ms |
29816 KB |
Output is correct |
18 |
Correct |
112 ms |
28024 KB |
Output is correct |
19 |
Runtime error |
114 ms |
48760 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
29048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
29048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |