题目来源:

pid=3118">HDU 3118 Arbiter

题意:翻译过来就是不能有奇圈 每走一步状态会变化 当他回到起点时假设和原来的状态不一样 可能会死 求至少去掉多少条边能够避免这样的状况发生

思路:二分图是没有奇圈的 最多就15个点 我们用状态压缩枚举那些点是在二分图的一边和另外一边 确定二分图之后枚举输入的边 每条边连接的不能是同一集合的点

不符合就去掉 最后取小

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 510;
struct node
{
int t1, t2, x1, y1, x2, y2;
}a[maxn];
int vis[maxn];
int y[maxn];
vector <int> G[maxn];
int n; int color[maxn];
int sum = 0; bool dfs(int u)
{
for(int i = 0; i < G[u].size(); i++)
{
int v = G[u][i];
if(vis[v])
continue;
vis[v] = true;
if(y[v] == -1 || dfs(y[v]))
{
y[v] = u;
return true;
}
}
return false;
}
int match()
{
int ans = 0;
memset(y, -1, sizeof(y));
for(int i = 0; i < n; i++)
{
memset(vis, 0, sizeof(vis));
if(dfs(i))
ans++;
}
return ans;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int m;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++)
G[i].clear();
while(m--)
{
int u, v;
scanf("%d %d", &u, &v);
G[u].push_back(v);
//G[v].push_back(u);
}
int ans = 999999999;
for(int s = 0; s < (1<<n); s++)
{
memset(color, 0, sizeof(color));
for(int i = 0; i < n; i++)
if(s&(1<<i))
color[i] = 1;
sum = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < G[i].size(); j++)
if(color[i] == color[G[i][j]])
sum++;
ans = min(ans, sum);
}
printf("%d\n", ans);
}
return 0;
}

HDU 3118 Arbiter 判定奇圈的更多相关文章

  1. hdu 4598 Difference(奇圈判定+差分约束)

    这是通化邀请赛的题,当时比赛的时候还完全没想法呢,看来这几个月的训练还是有效果的... 题意要求(1) |ai| < T for all i   (2) (vi, vj) in E <=& ...

  2. hdu 3118 Arbiter

    http://acm.hdu.edu.cn/showproblem.php?pid=3118   题意:删除最少的边使图没有奇环   二分图的定义:如果顶点能分为两个互不相交的子集,则图为二分图 二分 ...

  3. POJ2942 Knights of the Round Table 点双连通分量,逆图,奇圈

    题目链接: poj2942 题意: 有n个人,能够开多场圆桌会议 这n个人中,有m对人有仇视的关系,相互仇视的两人坐在相邻的位置 且每场圆桌会议的人数仅仅能为奇书 问有多少人不能參加 解题思路: 首先 ...

  4. poj——3118 Arbiter

      Arbiter 题目描述:      “仲裁者”是<星际争霸>科幻系列中的一种太空船.仲裁者级太空船是神族的战船,专门提供精神力支援.不像其他战船的人员主要是战士阶级,仲裁者所承载的都 ...

  5. loj 1300( 边双联通 + 判奇圈 )

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27010 思路:首先Tarjan标记桥,然后对于dfs遍历整个图,我 ...

  6. lightoj 1300 边双联通分量+交叉染色求奇圈

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1300 边双连通分量首先dfs找出桥并标记,然后dfs交叉着色找奇圈上的点.这题只要求在 ...

  7. FZU2181+poj2942(点双连通+判奇圈)

    分析:我们对于那些相互不憎恨的人连边,将每次参加会议的所有人(不一定是全部人,只需人数>=3且为奇数)看做一个点双联通分量,那么每个点都至少有两个点与他相邻.即需要保证双联通分量中存在奇圈.至于 ...

  8. CF #311 D. Vitaly and Cycle 加最少边形成奇圈

    题目链接:http://codeforces.com/problemset/problem/557/D 大意 给出一个未必联通的无向图(点数至少为3),问最少加多少边可以形成一个奇圈,以及这样做的方案 ...

  9. poj 2942(点双连通+判奇圈)

    题目链接:http://poj.org/problem?id=2942 思路:我们对于那些相互不憎恨的骑士连边,将每次参加会议的所有人(不一定是整个骑士团,只需人数>=3且为奇数)看做一个点双联 ...

随机推荐

  1. python爬取博客圆首页文章链接+标题

    新人一枚,初来乍到,请多关照 来到博客园,不知道写点啥,那就去瞄一瞄大家都在干什么好了. 使用python 爬取博客园首页文章链接和标题. 首先当然是环境了,爬虫在window10系统下,python ...

  2. Django 千锋培训的学习笔记(2)

    Django 千锋培训读书笔记 https://www.bilibili.com/video/av17879644/?p=1 切换到创建项目的目录 cd C:\Users\admin\Desktop\ ...

  3. CodeForces:699B-One Bomb

    B. One Bomb time limit per test1 second memory limit per test256 megabytes Problem Description You a ...

  4. 几条sql语句(exists)

    通常exists后的子查询是需要和外面的表建立关联关系的,如 select count(*) from a where exists (select 'x' from b where a.id = b ...

  5. luogu3755 [CQOI2017]老C的任务

    扫描线水题. #include <algorithm> #include <iostream> #include <cstdio> using namespace ...

  6. 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛

    Banana Bananas are the favoured food of monkeys. In the forest, there is a Banana Company that provi ...

  7. 九度oj 题目1024:畅通工程

    题目描述:     省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).经过调查评估,得到的统计表中列出了有可能建设公路的若干条道 ...

  8. BZOJ 1861 [Zjoi2006]Book 书架 ——Splay

    [题目分析] 模板题目. 首尾两个虚拟结点,十分方便操作. [代码] #include <cstdio> #include <cstring> #include <cma ...

  9. cf711E ZS and The Birthday Paradox

    ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...

  10. LightOJ1106 Gone Fishing

    Gone Fishing John is going on a fishing trip. He has h hours available, and there are n lakes in the ...