1009 - Back to Underworld(二分图染色)

本文探讨了一种方法,通过分析不同种族之间的战斗记录,来预测最终存活的最大种族成员数量。通过输入战斗数量及参与者的具体对战信息,算法能够高效计算出可能的种族规模。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://www.lightoj.com/volume_showproblem.php?problem=1009


1009 - Back to Underworld
Time Limit: 4 second(s)Memory Limit: 32 MB

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 <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#define SI(T)int T;scanf("%d",&T)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
const int SIZE=2e4+10;
const int maxn=1<<30;
int vis[SIZE];
int node[SIZE];
int sum_tot[SIZE][2];
vector<vector<int> >G;
void bfs(int s,int tot){
    queue<int> q;
    q.push(s);
    vis[s]=1;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        sum_tot[tot][vis[u]]++;
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i];
            if(vis[v]!=-1)continue;//匹配过了return false;
            q.push(v);
            vis[v]=vis[u]^1;
        }
    }
    return;
}
int main()
{
    SI(T);
    for(int cas=1;cas<=T;cas++){
        G.clear();
        G.resize(SIZE);
        memset(vis,0,sizeof(vis));
        int n,u,v,cnt=0;
        scanf("%d",&n);
        while(n--){
            scanf("%d%d",&u,&v);
            if(!vis[u]){
                node[cnt++]=u;
                vis[u]=1;
            }
            if(!vis[v]){
                node[cnt++]=v;
                vis[v]=1;
            }
            G[u].push_back(v);
            G[v].push_back(u);
        }
        int tot=0;
        memset(vis,-1,sizeof(vis));
        memset(sum_tot,0,sizeof(sum_tot));
        for(int i=0;i<cnt;i++){
            int x=node[i];
            if(vis[x]==-1){
                bfs(x,tot++);
            }
        }
        int ans=0;
        for(int i=0;i<tot;i++){
            ans+=max(sum_tot[i][0],sum_tot[i][1]);
        }
        printf("Case %d: %d\n",cas,ans);
    }
    return 0;
}


### 中职学校网络安全理论课程大纲和教学内容 #### 2025年中职学校网络安全理论课程概述 随着信息技术的发展网络安全已成为信息化社会的重要组成部分。为了适应这一需求,中职学校的网络安全理论课程旨在培养学生具备基本的网络安全意识和技术能力,使学生能够在未来的职业生涯中应对各种网络威胁。 #### 教学目标 该课程的目标是让学生理解网络安全的基本概念、原理和技术手段,掌握常见的安全防护措施,并能应用这些知识解决实际问题。具体来说,学生应达到以下几点: - 掌握计算机网络基础架构及其工作原理; - 理解信息安全管理体系框架及其实现方法; - 学习密码学基础知识以及加密算法的应用场景; - 能够识别常见攻击方式并采取有效防御策略; #### 主要章节安排 ##### 第一章 计算机网络与互联网协议 介绍计算机网络的基础结构和服务模型,重点讲解TCP/IP五层体系结构中的各层次功能特点,特别是传输控制协议(TCP)和用户数据报协议(UDP)[^1]。 ##### 第二章 信息系统安全保障概论 探讨信息系统的脆弱性和风险评估机制,阐述如何通过物理隔离、访问控制等措施来保障系统安全性。 ##### 第三章 密码学入门 讲述对称密钥体制和非对称密钥体制的区别与发展历程,分析公钥基础设施(PKI)的工作流程及其重要性。 ##### 第四章 防火墙技术与入侵检测系统(IDS) 解释防火墙的作用原理及其分类形式(包过滤型、代理服务器型),讨论IDS的功能特性及部署建议。 ##### 第五章 Web应用程序安全 针对Web环境下的特殊挑战展开论述,如SQL注入漏洞利用、跨站脚本(XSS)攻击防范等内容。 ##### 实践环节设置 除了上述理论部分外,在每学期还设有专门实践课时用于模拟真实环境中可能遇到的安全事件处理过程,增强学生的动手操作能力和应急响应水平。 ```python # Python代码示例:简单的MD5哈希函数实现 import hashlib def md5_hash(text): hasher = hashlib.md5() hasher.update(text.encode('utf-8')) return hasher.hexdigest() print(md5_hash("example")) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值