the
A non-direction graph, no heavy edge, and a self loop are given.
Ask how many sides of the two-tuple <e1,e2> meet a path in the diagram, where E1,e2 e1,e2 are just passing through one time, the other m−2 m-2 bar just after two times.
n,m≤100000 n,m \le 100000
Give each edge a side, and then the problem is converted to: Cancel the two-piece patch, so that the number of odd points is 0 0 or 2 2 of the number of scenarios.
Obviously, before the edge is removed, the degrees of all points are even, and when one edge is deleted, two odd points appear. When you delete an edge, there will be a public endpoint on the side, or 4 4 odd points.
Then just enumerate the first side and XJB XJB statistics.
Pay attention to dealing with the self loop, and whether the diagram has no solution.
#include <cstdio> #include <cmath> #include <algorithm> using namespace std;
typedef long Long LL;
const int maxn=1000005;
int N,M,_M,CNT,D[MAXN],FA[MAXN];
BOOL VIS[MAXN]; struct edge{int x,y;}
ES[MAXN];
LL ans; int GETFA (int x) {return FA[X]==X?X:FA[X]=GETFA (fa[x]);} void merge (int x,int y) {X=GETFA (x); Y=getfa (y); if (x!=y) fa[x]= Y
int main () {//freopen ("cf788b.in", "R", stdin);
Freopen ("Cf788b.out", "w", stdout);
scanf ("%d%d", &n,&m);
for (int i=1;i<=n;i++) fa[i]=i;
for (int i=1;i<=m;i++) {int x,y; scanf ("%d%d", &x,&y);
if (x!=y) {es[++_m].x=x, es[_m].y=y; d[x]++; d[y]++;
Vis[x]=vis[y]=true;
Merge (X,y);
else cnt++, vis[x]=true; int rt=0;
for (int i=1;i<=n;i++) if (vis[i]) rt=i;
if (!RT) return printf ("0\n"), 0;
for (int i=1;i<=n;i++) if (VIS[I]&&GETFA (RT)!=GETFA (i)) return printf ("0\n"), 0; for (int i=1;i<=_m;i++) ans+= (d[es[i].x]-1) + (d[es[i].y]-1);
ans=ans/2+ (LL) _m*cnt+ (LL) cnt* (cnt-1)/2;
printf ("%i64d\n", ans);
return 0; }