#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;
#define FOR(i,b,e) for(int i = (b); i < (e); i++)
#define TRAV(x,a) for(auto &x: (a))
#define SZ(x) ((int)x.size())
#define PB push_back
#define X first
#define Y second
const int N = 2e5+5;
vector<ii> G[N];
bool blocked[N*3];
int bridges, tim;
int in[N], low[N];
void dfs(int v, int id){
in[v] = low[v] = ++tim;
TRAV(x, G[v]){
if(x.Y == id || blocked[x.Y]) continue;
if(!in[x.X]){
dfs(x.X, x.Y);
low[v] = min(low[v], low[x.X]);
if(in[v] < low[x.X]) bridges++;
}
low[v] = min(low[v], in[x.X]);
}
}
void readInt(int &x){
x = 0;
char c = getchar();
bool negative = 0;
while(c < 33) c = getchar();
if(c == '-') negative = 1, c = getchar();
while('0' <= c && c <= '9') x = 10*x + c - '0', c = getchar();
if(negative) x *= -1;
}
void solve(){
int n, m;
ll ans = 0;
readInt(n), readInt(m);
FOR(i, 0, m){
int a, b;
readInt(a), readInt(b);
G[a].PB({b, i});
G[b].PB({a, i});
}
FOR(i, 0, m){
blocked[i] = 1;
FOR(j, i+1, m){
blocked[j] = 1;
bridges = tim = 0;
FOR(v, 1, n+1) in[v] = low[v] = 0;
dfs(1, -1);
FOR(v, 2, n+1) if(!in[v]){
bridges = m-2;
break;
}
ans += bridges;
blocked[j] = 0;
}
blocked[i] = 0;
}
cout << ans/3 << '\n';
}
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// int tt; cin >> tt;
// FOR(te, 0, tt)
solve();
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; const int INF = 0x3f3f3f3f; #define FOR(i,b,e) for(int i = (b); i < (e); i++) #define TRAV(x,a) for(auto &x: (a)) #define SZ(x) ((int)x.size()) #define PB push_back #define X first #define Y second const int N = 2e5+5; vector<ii> G[N]; bool blocked[N*3]; int bridges, tim; int in[N], low[N]; void dfs(int v, int id){ in[v] = low[v] = ++tim; TRAV(x, G[v]){ if(x.Y == id || blocked[x.Y]) continue; if(!in[x.X]){ dfs(x.X, x.Y); low[v] = min(low[v], low[x.X]); if(in[v] < low[x.X]) bridges++; } low[v] = min(low[v], in[x.X]); } } void readInt(int &x){ x = 0; char c = getchar(); bool negative = 0; while(c < 33) c = getchar(); if(c == '-') negative = 1, c = getchar(); while('0' <= c && c <= '9') x = 10*x + c - '0', c = getchar(); if(negative) x *= -1; } void solve(){ int n, m; ll ans = 0; readInt(n), readInt(m); FOR(i, 0, m){ int a, b; readInt(a), readInt(b); G[a].PB({b, i}); G[b].PB({a, i}); } FOR(i, 0, m){ blocked[i] = 1; FOR(j, i+1, m){ blocked[j] = 1; bridges = tim = 0; FOR(v, 1, n+1) in[v] = low[v] = 0; dfs(1, -1); FOR(v, 2, n+1) if(!in[v]){ bridges = m-2; break; } ans += bridges; blocked[j] = 0; } blocked[i] = 0; } cout << ans/3 << '\n'; } int main(){ // ios::sync_with_stdio(0); // cin.tie(0); // int tt; cin >> tt; // FOR(te, 0, tt) solve(); return 0; } |
English