#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
//#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
int n, m;
const int N = 1e5 + 5;
vector<int> adj1[N];
bool mark[N];
int h[N];
int par[N];
int up[N];
vector<int> adj2[2 * N];
bool mark2[2 * N];
int block[N];
int bcnt[N];
int len[2 * N];
int par2[2 * N];
int mull(int a, int b) {
return (1ll * a * b) % mod;
}
void init() {
}
void input() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
// u = i; v = i + 1;
adj1[u].pb(v);
adj1[v].pb(u);
}
}
void dfshp(int u) {
mark[u] = true;
for (auto v : adj1[u]) {
if (!mark[v]) {
h[v] = h[u] + 1;
par[v] = u;
dfshp(v);
}
}
}
void dfsup(int u) {
mark[u] = true;
up[u] = h[u];
for (auto v : adj1[u]) {
if (!mark[v]) {
dfsup(v);
up[u] = min(up[u], up[v]);
}
else {
up[u] = min(up[u], h[v]);
}
}
}
void dfsbd(int u) {
mark[u] = true;
for (auto v : adj1[u]) {
if (!mark[v]) {
if (up[v] == h[u]) {
block[v] = v;
bcnt[v] = 1;
}
else {
block[v] = block[u];
}
dfsbd(v);
}
}
}
void dfslen(int u) {
if (u <= n) {
len[u] = bcnt[u];
}
else {
len[u] = 1;
}
for (auto v : adj2[u]) {
if (v != par2[u]) {
par2[v] = u;
dfslen(v);
len[u] += len[v] - 1;
}
}
}
void solve() {
fill(mark + 1, mark + n + 1, false);
dfshp(1);
for (int i = 1; i <= n; i++) {
if (!mark[i]) {
throw;
}
}
fill(mark + 1, mark + n + 1, false);
dfsup(1);
fill(mark + 1, mark + n + 1, false);
dfsbd(1);
for (int u = 1; u <= n; u++) {
bcnt[block[u]]++;
}
bcnt[0] = 0;
for (int u = 1; u <= n; u++) {
bool cut = false;
for (auto v : adj1[u]) {
if (par[v] == u && block[v] == v) {
cut = true;
}
}
if (cut) {
adj2[block[u]].pb(u + n);
adj2[u + n].pb(block[u]);
}
if (block[u] == u) {
adj2[block[u]].pb(par[u] + n);
adj2[par[u] + n].pb(block[u]);
}
}
dfslen(1 + n);
//return;
int ans = mull(n, mull(n - 1, n - 2));
// cout << ans << endl;
for (int u = 1; u <= n; u++) {
if (!len[u]) {
continue;
}
for (auto v : adj2[u]) {
// cout << " " << u << ' ' << v << ' ' << par2[u] << ' ' << bcnt[u] - 1 << ' ' << mull(len[v], len[v] - 1) << endl;
if (par2[u] != v) {
ans -= mull(bcnt[u] - 1, mull(len[v], len[v] - 1));
ans %= mod;
}
}
// cout << " " << u << ' ' << bcnt[u] - 1 << ' ' << n - len[u] + 1 << endl;
ans -= mull(bcnt[u] - 1, mull(n - len[u] + 1, n - len[u]));
ans %= mod;
}
ans += mod;
ans %= mod;
cout << ans;
}
void output() {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int number_of_testcases = 1;
//cin >> number_of_testcases;
while (number_of_testcases--) {
init();
input();
solve();
output();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
91 ms |
18820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7436 KB |
Output is correct |
2 |
Correct |
5 ms |
7444 KB |
Output is correct |
3 |
Correct |
5 ms |
7524 KB |
Output is correct |
4 |
Correct |
5 ms |
7636 KB |
Output is correct |
5 |
Correct |
5 ms |
7612 KB |
Output is correct |
6 |
Correct |
4 ms |
7508 KB |
Output is correct |
7 |
Correct |
5 ms |
7508 KB |
Output is correct |
8 |
Correct |
5 ms |
7516 KB |
Output is correct |
9 |
Correct |
6 ms |
7484 KB |
Output is correct |
10 |
Runtime error |
10 ms |
14880 KB |
Execution killed with signal 6 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
123 ms |
19400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7512 KB |
Output is correct |
2 |
Correct |
7 ms |
7428 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
4 |
Correct |
5 ms |
7460 KB |
Output is correct |
5 |
Correct |
5 ms |
7380 KB |
Output is correct |
6 |
Correct |
5 ms |
7420 KB |
Output is correct |
7 |
Correct |
6 ms |
7380 KB |
Output is correct |
8 |
Correct |
5 ms |
7380 KB |
Output is correct |
9 |
Correct |
5 ms |
7384 KB |
Output is correct |
10 |
Correct |
4 ms |
7380 KB |
Output is correct |
11 |
Correct |
6 ms |
7380 KB |
Output is correct |
12 |
Correct |
5 ms |
7508 KB |
Output is correct |
13 |
Correct |
7 ms |
7508 KB |
Output is correct |
14 |
Correct |
5 ms |
7508 KB |
Output is correct |
15 |
Correct |
5 ms |
7512 KB |
Output is correct |
16 |
Runtime error |
11 ms |
14808 KB |
Execution killed with signal 6 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
130 ms |
19336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
14676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |