LOJ 1009 - Back to Underworld(二分图染色)
来源:互联网 发布:网络通讯设备制造厂商 编辑:程序博客网 时间:2024/05/22 15:20
The Vampires and Lykans are fighting each other to death. The war has become so fierce that, none knows who will win. The humans want to know who will survive finally. But humans are afraid of going to the battlefield.
So, they made a plan. They collected the information from the newspapers of Vampires and Lykans. They found the information about all the dual fights. Dual fight means a fight between a Lykan and a Vampire. They know the name of the dual fighters, but don't know which one of them is a Vampire or a Lykan.
So, the humans listed all the rivals. They want to find the maximum possible number of Vampires or Lykans.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 105), denoting the number of dual fights. Each of the next n lines will contain two different integers u v (1 ≤ u, v ≤ 20000) denoting there was a fight between u and v. No rival will be reported more than once.
Output
For each case, print the case number and the maximum possible members of any race.
Sample Input
Output for Sample Input
2
2
1 2
2 3
3
1 2
2 3
4 2
Case 1: 2
Case 2: 3
Note
Dataset is huge, use faster I/O methods.
题意:问其中两个种族的数目较大的那个值最大可能是多少
#include<cstdio>#include<cstring>#include<vector>#include<iostream>#include<algorithm>using namespace std;const int maxn = 20010;vector<int> G[maxn];int v;int color[maxn]; // 染色为1和-1bool vis[maxn]; // 记录该点是否存在int sum,sum1;bool dfs(int v,int c){ sum++; if(c == 1) sum1++; color[v] = c; for(int i = 0 ; i < G[v].size() ; i++) { if(color[G[v][i]]) continue; dfs(G[v][i],-c); }}int main(){ int t,n,kcase = 1; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(color,0,sizeof(color)); memset(vis,false,sizeof(vis)); for(int i = 1 ; i <= maxn ; i++) G[i].clear(); int maxx = 0; int minn = maxn; for(int i = 0 ; i < n ; i++) { int x,y; scanf("%d%d",&x,&y); vis[x] = vis[y] = true; G[x].push_back(y); G[y].push_back(x); maxx = max(max(maxx,x),y); minn = min(min(minn,x),y); } int ans = 0; for(int i = minn ; i <= maxx ; i++) { if(!vis[i] || color[i] != 0) continue; sum = sum1 = 0; dfs(i,1); ans += max(sum1,sum-sum1); } printf("Case %d: %d\n",kcase++,ans); } return 0;}
- LOJ 1009 - Back to Underworld(二分图染色)
- LightOJ1009-Back to Underworld -二分图染色
- LightOJ - 1009 Back to Underworld(二分图染色)
- 1009 - Back to Underworld(二分图染色)
- 【Lightoj 1009 Back to Underworld】+ 二分图染色
- lightoj 1009 - Back to Underworld(二分图染色)
- LightOJ-1009-Back to Underworld [二分图染色]
- LightOJ1009---Back to Underworld (bfs染色)
- LightOJ 1009 Back to Underworld
- Light OJ 1009 - Back to Underworld
- Light 1009 - Back to Underworld (dfs)
- Lightoj--1009--Back to Underworld(dfs)
- lightoj 1009 - Back to Underworld 【DFS】
- LightOJ 1009 Back to Underworld 搜索
- Back to Underworld
- Back to Underworld
- lightoj1009 - Back to Underworld【dfs】
- LightOJ 1009 Back to Underworld (种类并查集)
- PAT 1047To Fill or Not to Fill (25)(高速公路加油问题)
- UVA 12589 Learning Vector
- 学习网络编程很好的网站
- mimeTypes
- 一种注册后自动登录CAS单点登录系统的方法
- LOJ 1009 - Back to Underworld(二分图染色)
- Android自定义底部弹出Dialog
- blog,你知道的
- caffe 准确率一直震荡,从0到0.6反复
- Python paramiko SFTP协议上传下载文件
- NDK-JNI之初体验
- 【框架-MFC】启动异常- 读取位置 0xfeeefef2 时发生访问冲突
- 记录些多而杂的知识,持续更新
- Error: NDK integration is deprecated in the current plugin.