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. 使用mpxj读取MSPrjoect

    import java.util.ArrayList; import java.util.Calendar; import java.util.Hashtable; import java.util. ...

  2. 视频生成 量产 win 转 linux ffmpeg linux 安装 对批量视频的尽可能短时间生成

    环境准备 Welcome to aliyun Elastic Compute Service! [root@mytest ~]# pip install baidu-aip Looking in in ...

  3. ZOJ 3609 Modular Inverse(扩展欧几里德)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4712 The modular modular multiplicat ...

  4. uboot中添加自己的命令【转】

    本文转载自:http://blog.csdn.net/huanghai381/article/details/51206646 每个命令都是通过U_BOOT_CMD宏来定义的.这个宏定义了一个相关的结 ...

  5. T4 最小差异值 dvalue

    T4 最小差异值 dvalue [问题描述] P 省刚经历一场不小的地震,所有城市之间的道路都损坏掉了,所以省长想请你将城市之间的道路重修一遍. 因为很多城市之间的地基都被地震破坏导致不能修公路了,所 ...

  6. golang中管道热替换

    golang中管道替换问题 https://blog.csdn.net/cyk2396/article/details/78875347 1.运行以下代码: var chan1 chan int va ...

  7. 10.07 WZZX Day2总结

    今天仍然是KCZ出题.今天才知道KCZ不仅是WZ地区史上最强选手而且还是ZJ队长?在ZJOI拿到Rank1的男人?%%%%% 今天KCZ出题的依然很强势…… T1.wzoi 期望得分20-100 实际 ...

  8. 洛谷 P2038 无线网络发射器选址 —— 二维树状数组

    题目:https://www.luogu.org/problemnew/show/P2038 大水题暴露出我的愚蠢. 用二维树状数组,然而居然忘了它应该那样写,调了一个小时: 正方形可以超出外面,只要 ...

  9. bzoj1875 [SDOI2009]HH去散步——矩阵快速幂

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1875 有个限制是不能走回头路,比较麻烦: 所以把矩阵中的元素设成边的经过次数,单向边之间就好 ...

  10. JavaScript代码优化新工具UglifyJS

    jQuery 1.5 发布的时候 john resig 大神说所用的代码优化程序从Google Closure切换到UglifyJS,新工具的压缩效果非常令人满意. UglifyJS 是一个服务端no ...