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. pat(A) 1063. Set Similarity(STL)

    代码: #include<cstdio> #include<cstring> #include<set> using namespace std; set<i ...

  2. javascript下获取guid或者UTC时间作为唯一值

    javascript下,有时出于需要,可以利用guid或UTC时间作为当前页面中的唯一值. 什么场景需要弄这个唯一值? 比如说,用easyUI的treegrid,添加新节点.在treegrid里面 , ...

  3. 【bzoj3124】[Sdoi2013]直径

    1.求树的直径: 先随便取一个点,一遍dfs找到离它最远的点l1,再以l1为起点做一遍dfs,找到离l1最远的点l2   那么l1到l2的距离即为直径   2. 求出有多少条边在这棵树的所有直径上:  ...

  4. gcc的搜索路径,头文件和库

    1 抛开默认的搜索路径,自己指定搜索路径 第一,明确自己编写的代码所需要的头文件和库放在了哪里 第二,使用“-I”指定头文件的搜索路径,使用-rpath指定库的搜索路径 2 无论是本地编译还是交叉编译 ...

  5. PHP博客项目-gai

    XX科技还是米有电话过来,看样子真的是黄了.这段时间都没有好好学习,经历了两次稀里糊涂的面试,特别是第二次,让我感觉自己之前学的东西都已经忘了,本来就学的不多,也不扎实,还一忘...看了是真的要开始着 ...

  6. WinForm里面连接Oracle数据库

    WinForm里面连接Oracle数据库 string oradb = "Data Source=(DESCRIPTION="             + "(ADDRE ...

  7. luogu 2627 修建草坪

    题目大意: 一个数列,取出一些数使得它们的总和最大且没有k个连续 思路: 首先我们可以找到一个nk的dp dp方程:dp[i]=dp[i-1]+sum[i]-sum[j] (sum[j]尽量小) 然后 ...

  8. TypeError: expected bytes-like object, not str

    报错内容:TypeError: expected bytes-like object, not str 例: a = base64.b64encode(temp) 改为: a = base64.b64 ...

  9. bzoj1791

    1791: [Ioi2008]Island 岛屿 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 1680  Solved: 369[Submit][S ...

  10. [Swift通天遁地]一、超级工具-(15)使用SCLAlertView制作强大的Alert警告窗口和Input编辑窗口

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...