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的更多相关文章

  1. HDU多校Round 8

    Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...

  2. HDU多校Round 7

    Solved:2 rank:293 J. Sequense 不知道自己写的什么东西 以后整数分块直接用 n / (n / i)表示一个块内相同n / i的最大i #include <bits/s ...

  3. HDU多校Round 5

    Solved:3 rank:71 E. Everything Has Changed #include <bits/stdc++.h> using namespace std; const ...

  4. HDU多校Round 4

    Solved:3 rank:405................................. B. Harvest of Apples 知道了S(n,m) 可以o(1)的求S(n - 1, m ...

  5. HDU多校Round 3

    Solved:4 rank:268 C. Dynamic Graph Matching  状压DP一下 #include <stdio.h> #include <algorithm& ...

  6. HDU多校Round 1

    Solved:5 rank:172 A.Maximum Multiple #include <stdio.h> #include <algorithm> #include &l ...

  7. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  8. hdu 5643 BestCoder Round #75

    King's Game  Accepts: 249  Submissions: 671  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6 ...

  9. hdu 5641 BestCoder Round #75

    King's Phone  Accepts: 310  Submissions: 2980  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. Linux 编译C++ 与 设置 Vim

    1. Linux 下编译c++ vim test.cpp    // 创建文件 g++ test.cpp    // 编译文件 ./a.out         // 执行文件 g++ test.cpp ...

  2. Java语言中extend和implement的区别

    Java语言并不支持多重继承,而只能继承一个类,不过我们可以使用implements来实现多个接口. extends继承的父类:不能声明为final或者定义为abstract: implements实 ...

  3. ubuntu12.04通过Ganglia利用NVML模块进行GPU监控

    1.安装Ganglia,这里安装的是3.1*版本,因为监控GPU的模块只支持3.1*版本系列的 apt-get install ganglia* 2.下载并安装PyNVML和NVML模块,下载地址ht ...

  4. HNOI模拟 Day3.23

    一.拓扑(top)[ 题目描述]:给你一个有向二分图,求他的拓扑序列的个数.[ 输入]:第一行两个数 N,M,表示点数和边数.接下来 M 行每行两个数 a,b,表示 a 向 b 有一条有向边.[ 输出 ...

  5. hdoj--2186--悼念512汶川大地震遇难同胞——一定要记住我爱你(模拟水题)

     悼念512汶川大地震遇难同胞--一定要记住我爱你 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  6. Django的CBV方式讲解

    CBV使用配置 路径url的配置 cbv 顾名知义就是通过类的方法来调用,我们在url中配置为如下路径 url(r'^cbv.html/', views.Cbv.as_view()), 这里的Cbv是 ...

  7. matlab采用mex编译多个cpp文件

    最近在看matlab code时,由于本人使用的是64系统,而code中的mex文件时在32位系统上编译的,所以需要重新自己编译maxflowmex.cpp,但是直接mex maxflowmex.cp ...

  8. STM32:片上Flash 操作

    之前IAP时候记录过一些,今天对特定地方写又加深了印象,写与擦除都需要先unclock //读取指定地址的半字(16位数据) //faddr:读地址(此地址必须为2的倍数!!) //返回值:对应数据. ...

  9. 使用IntelliJ IDEA 配置JDK(入门)

    一.JDK下载 首先要下载java开发工具包JDK,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 点击 ...

  10. bzoj 1087: [SCOI2005]互不侵犯King【状压dp】

    显然是状压,设f[i][j][k]为1到i行选j个king,并且第i行状态为k的方案数,判断是否可行然后枚举转移即可 先把可行状态预处理出来会变快 #include<iostream> # ...