【题目链接】:http://codeforces.com/problemset/problem/789/D

【题意】



给你n个点,m条边;

可能会有自环

问你有没有经过某两条边各一次,然后剩余m-2条边,每条边各2次的

遍历方案,有的话输出方案数

【题解】

/*
把每条边都复制一条相同的边;
然后问题就能转化为在2*m条边中,去掉两条边;
然后使得剩下的图能够进行一笔画(每条边都只经过一次)
则使奇点的个数为0或为2就好了;
考虑自环边和普通边;
对于普通边来说:
①如果删掉的两条普通边是不相邻的两条边;
那么会有4个点变成奇点->排除
②如果删掉的两条普通边是相邻的两条边
则x-y-z中x和z会变成奇点;y仍旧是偶点;
刚好形成了两个奇点->符合要求
③考虑两条不同的自环边,如果删掉之后
每条自环边的端点两边都是同一个点,则每个点度数都减少2;
则每个点还都是偶点->奇点个数为0->符合
④一条自环边和一条普通边
普通边两边的点都变成奇点
->自环边两边的点是同一个点那个点度数-2还是偶点;
->总共两个奇点
还是符合题意
综上只要考虑
自环边和自环边
相邻的普通边
自环边和普通边
3种情况
如果没有联通的话得输出0
这里的联通只考虑m条边中出现过的点哦;
只要那些点联通就可以了

【Number Of WA】



3



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100; int n,m,ltk;
int f[N];
LL zh,ptb,ans,bian[N];
bool bo[N]; int zbb(int x)
{
if (f[x]==x)
return x;
else
return f[x] = zbb(f[x]);
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf就别用了!
cin >> n >> m;
ltk = n;
rep1(i,1,n) f[i] = i;
rep1(i,1,m)
{
int x,y;
cin >> x >> y;
bo[x] = true,bo[y] = true;
if (x==y)
{
zh++;
continue;
}
ptb++;
bian[x]++,bian[y]++;
int r1 = zbb(x),r2 = zbb(y);
if (r1!=r2)
{
ltk--;
f[r1] = r2;
}
}
rep1(i,1,n)
if (!bo[i])
ltk--;
if (ltk!=1)
return cout << 0 << endl,0;
//自环和自环
ans+=zh*(zh-1)/2;
//自环和普通边
ans+=zh*ptb;
//相邻的普通边
rep1(i,1,n)
ans+=bian[i]*(bian[i]-1)/2;
cout << ans << endl;
return 0;
}

【codeforces 789D】Weird journey的更多相关文章

  1. 【codeforces 779B】Weird Rounding

    [题目链接]:http://codeforces.com/contest/779/problem/B [题意] 问你要删掉几个数字才能让原来的数字能够被10^k整除; [题解] /* 数字的长度不大; ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【cf789D】Weird journey(欧拉路、计数)

    cf788B/789D. Weird journey 题意 n个点m条边无重边有自环无向图,问有多少种路径可以经过m-2条边两次,其它两条边1次.边集不同的路径就是不同的. 题解 将所有非自环的边变成 ...

  4. 【codeforces 757B】 Bash's Big Day

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 604D】Moodular Arithmetic

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 750B】New Year and North Pole

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

随机推荐

  1. MySQL 日期时间函数大全 (转)

    转载自:http://blog.itpub.net/29773961/viewspace-1808967 以下内容基于MySQL 5.6及更高,大部分函数5.5也基本适用,更低版本请参考对应版本手册, ...

  2. 一条SQL面试题

    求其中同一个主叫号码的两次通话之间间隔大于10秒的通话记录ID 例如:6,7,8,9,10条记录均符合 ID 主叫号码 被叫号码      通话起始时间            通话结束时间       ...

  3. mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析、统计功能,此外还支持本地集群部署管理.

    mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析.统计功能,此外还支持本地集群部署管理 https://www.cnblogs.com/littleatp/p/9 ...

  4. 【BZOJ 1598】 牛跑步

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1598 [算法] A*求k短路 [代码] #include<bits/stdc+ ...

  5. E - Perfect Number

    Problem description We consider a positive integer perfect, if and only if the sum of its digits is ...

  6. radis多个盘并发IO

    IO就是对磁盘的读/写. 一次IO,就是发出指令+执行命令. 磁盘IO的时间=寻道时间+数据传输时间 单盘不能并发IO. radis多个盘并发IO. 影响IO的最大因素是寻道时间. 影响电脑速度:cp ...

  7. Laravel5.1学习笔记9 系统架构1 请求生命周期 (待修)

    Request Lifecycle Introduction Lifecycle Overview Focus On Service Providers Introduction When using ...

  8. python特性小记(一)

    一.关于构造函数和析构函数 1.python中有构造函数和析构函数,和其他语言是一样的.如果子类需要用到父类的构造函数,则需要在子类的构造函数中显式的调用,且如果子类有自己的构造函数,必然不会自动调用 ...

  9. 【Linux】磁盘分区

    我们在Linux操作过程中,可能会遇到磁盘分区的问题.这篇文章是对/dev/sdb 这块磁盘进行分区. linux分区不同于windows,linux下硬盘设备名为(IDE硬盘为hdx(x为从a—d) ...

  10. 安卓系统使用摄像头API

    原文链接:定制自己的安卓Camera        参考链接:http://blog.csdn.net/tankai19880619/article/details/9075839           ...