HDU多校Round 6
Solved:2
rank:452
I. Werewolf
没有铁人 找铁狼 如果一个环中只有一条狼人边那个人就是铁狼
说铁狼是好人的人也是铁狼
#include <bits/stdc++.h>
using namespace std; int tmp, ans, lang;
char s[];
struct node
{
int to, nex, ty;
}E[];
int head[];
int col[];
int l[];
int r[]; void dfs(int x, int fa)
{
col[x] = tmp;
int c = head[x];
for(int i = c; i; i = E[i].nex)
{
int v = E[i].to;
if(v == fa) continue;
if(col[v]) continue;
dfs(v, x);
}
} void dfs1(int x, int fa)
{
ans++;
int c = head[x];
for(int i = c; i; i = E[i].nex)
{
int v = E[i].to;
if(v == fa) continue;
if(E[i].ty) dfs1(v, x);
}
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int cnt = ;
lang = tmp = ans = ;
int n; scanf("%d", &n);
memset(head, , sizeof(int) * (n + ));
memset(col, , sizeof(int) * (n + ));
for(int i = ; i <= n; i++)
{
int x; scanf("%d%s", &x, s);
if(s[] == 'v')
{
E[++cnt].to = x; E[cnt].nex = head[i]; E[cnt].ty = ; head[i] = cnt;
E[++cnt].to = i; E[cnt].nex = head[x]; E[cnt].ty = ; head[x] = cnt;
}
else
{
lang++;
l[lang] = i;
r[lang] = x;
}
} for(int i = ; i <= n; i++)
{
if(col[i]) continue;
tmp++;
dfs(i, );
} for(int i = ; i <= lang; i++)
if(col[l[i]] == col[r[i]]) dfs1(r[i], );
printf("0 %d\n", ans);
}
return ;
}
HDU多校Round 6的更多相关文章
- HDU多校Round 8
Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...
- HDU多校Round 7
Solved:2 rank:293 J. Sequense 不知道自己写的什么东西 以后整数分块直接用 n / (n / i)表示一个块内相同n / i的最大i #include <bits/s ...
- HDU多校Round 5
Solved:3 rank:71 E. Everything Has Changed #include <bits/stdc++.h> using namespace std; const ...
- HDU多校Round 4
Solved:3 rank:405................................. B. Harvest of Apples 知道了S(n,m) 可以o(1)的求S(n - 1, m ...
- HDU多校Round 3
Solved:4 rank:268 C. Dynamic Graph Matching 状压DP一下 #include <stdio.h> #include <algorithm& ...
- HDU多校Round 1
Solved:5 rank:172 A.Maximum Multiple #include <stdio.h> #include <algorithm> #include &l ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- hdu 5643 BestCoder Round #75
King's Game Accepts: 249 Submissions: 671 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6 ...
- hdu 5641 BestCoder Round #75
King's Phone Accepts: 310 Submissions: 2980 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- Unity3D & C# 设计模式--23
Unity3D & C#Design Patterns 23 design patterns. Creational Patterns 1. Abstract Factory抽象工厂 创 ...
- java 学习第一步---安装JDK以及配置环境变量
1.下载jdk 链接:https://pan.baidu.com/s/1FiTGhxdHK0KTFawdkLT26g 提取码:zcy0 我已经在官网上面下载了1.8的jdk,通过百度云盘分 ...
- Android学习笔记-传感器开发之利用传感器和Tween开发简易指南针
本次我们学习Android传感器的开发,前面已经介绍过了,tween的使用,所以,我们可以结合传感器与tween动画,开发简易的指南针. 首先先介绍一下传感器的相关知识, 在Android应用程序中使 ...
- c# Winform实现中国省份地图
1.利用raphael.js IE下的VML和SVG实现矢量地图 2.JS调用c# Winform代码,代码 [System.Runtime.InteropServices.ComVisibleAtt ...
- 以太网接口TCP/IP协议介绍,说的很容易懂了
以太网接口TCP/IP协议介绍,说的很容易懂了 TCP/IP协议,或称为TCP/IP协议栈,或互联网协议系列. TCP/IP协议栈(按TCP/IP参考模型划分) 应用层 FTP SMTP HTT ...
- 【Silverlight】Bing Maps学习系列(七):使用Bing Maps的图片系统(Tile System)
[Silverlight]Bing Maps学习系列(七):使用Bing Maps的图片系统(Tile System) 目前包括微软必应地图在内的几乎所有在线电子地图(如:Google Maps等)都 ...
- pycharm打开多个项目并存
问题: 有时我们需要打开多个项目,而现在的做法是: 原有的a项目不动,新打开一个pycharm来打开b项目, 或者 在原有的a项目中打开b项目并覆盖a项目,即a项目与b项目不能共存 需求: 有时我们 ...
- 将数据从数据仓库Hive导入到MySQL
1.启动Hadoop,hive,mysql 2.在mysql中建表(需要导入数据的) mysql> CREATE TABLE `dbtaobao`.`user_log` (`user_id` v ...
- 如何在 ubuntu 12.04 上安装 skype(转载)
转自:http://blog.51osos.com/linux/how-to-install-skype-in-ubuntu-12-04/ 添加Canonical Partner Repository ...
- Python机器学习算法 — 决策树(Decision Tree)
决策树 -- 简介 决策树(decision tree)一般都是自上而下的来生成的.每个决策或事件(即自然状态)都可能引出两个或多个事件,导致不同的结果,把这种决策分支画成图形很像一棵 ...