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. 华为OJ:数字颠倒

    将数字转成一个字符串即可了. import java.util.Scanner; public class convertNumber { public static void main(String ...

  2. ios30---pthread, NSThread, GCD, NSOperation

    pthread(线程库,很早就有的技术,了解):一套通用的多线程API适用于Unix\Linux\Windows等系统(java开发也有pthread)跨平台\可移植使用难度大(全是C函数) C语言 ...

  3. java操作linux,调用shell命令

    import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.IOException; import ...

  4. Mac下搭建react native开发环境

    安装必需软件 Homebrew Homebrew, Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件. /usr/bin/ruby -e "$(curl -fsSL htt ...

  5. [2017SEERC]Divide and Conquer

    https://www.zybuluo.com/ysner/note/1308834 题面 一个有\(n\)个点的图,上面有有两棵不同的生成树.问至少切断几条边,可以使原图不联通.并输出方案数. \( ...

  6. POJ2187 Beauty Contest (旋转卡壳算法 求直径)

    POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...

  7. 解决 IDEA 中文乱码

    一.打开Intellij的根目录,找到下图的两个文件(根据你的系统是32位或64位选择其中一个配置文件),在配置文件中添加:-Dfile.encoding=UTF-8 二.   配置IDE编码 点击F ...

  8. L1范数和L2范数

    给定向量x=(x1,x2,...xn)L1范数:向量各个元素绝对值之和L2范数:向量各个元素的平方求和然后求平方根Lp范数:向量各个元素绝对值的p次方求和然后求1/p次方L∞范数:向量各个元素求绝对值 ...

  9. bzoj 1703: [Usaco2007 Mar]Ranking the Cows 奶牛排名【bitset+Floyd传递闭包】

    把关系变成有向边,稍微想一下就是要求在有向图中不能到达的点对个数,这个可以用Floyd传递闭包来做,但是n^3的复杂度跑不了1000 考虑bitset优化! 因为传递过程只会出现0和1,用bitset ...

  10. bzoj 1623: [Usaco2008 Open]Cow Cars 奶牛飞车【排序+贪心】

    从小到大排个序,然后能选就选 #include<iostream> #include<cstdio> #include<algorithm> using names ...