CF316D
来源:互联网 发布:tensorflow 数据结构 编辑:程序博客网 时间:2024/06/13 02:59
//大半夜的来写一发题解
//教会我了怎么用vector的二分函数/(ㄒoㄒ)/~~
//主要是dfs序啦。。。
详细的可以在代码中感觉
#include <iostream>#include<stdio.h>#include<string.h>#include<vector>#include<algorithm>using namespace std;const int maxn=500000+10;int head[maxn];int to[maxn];int next[maxn];int cnt;int tot;char str[maxn];void init(){ tot=0; cnt=0; memset(head,-1,sizeof(head));}void addedge(int u,int v){ to[tot]=v; next[tot]=head[u]; head[u]=tot++;}int start[maxn],ed[maxn];vector<int>tt[maxn][27];vector<int>::iterator it1,it2;void dfs(int u,int deep){ tt[deep][str[u]-'a'].push_back(++cnt); start[u]=cnt; for(int i=head[u];i!=-1;i=next[i]) { dfs(to[i],deep+1); } ed[u]=cnt;}int main(){ init(); int n,m; scanf("%d%d",&n,&m); for(int i=2;i<=n;i++) { int v; scanf("%d",&v); addedge(v,i); } scanf("%s",str+1); dfs(1,1); for(int i=1;i<=m;i++) { int h,v; scanf("%d%d",&v,&h); int k=0; for(int i=0;i<26;i++) { it1=lower_bound(tt[h][i].begin(),tt[h][i].end(),start[v]); it2=upper_bound(tt[h][i].begin(),tt[h][i].end(),ed[v]); if((it2-it1)&1) { k++; if(k>1) break; } } if(k<=1) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- CF316D
- 反射调用方法和反射时传递带参数的构造器
- 面向对象(Static关键字+main函数)-第12天
- Java读取Properties文件并不会出现中文乱码
- 开源Word读写组件DocX 的深入研究和问题总结
- Win32内存结构
- CF316D
- linux下的nfc开发
- 动态规划 | 带有通配符的字符串匹配(浅显易懂)
- 数据结构--队列
- [latex] 格式控制
- LeetCode 题解(171): Jump Game
- 【LeetCode-面试算法经典-Java实现】【129-Sum Root to Leaf Numbers(所有根到叶子结点组组成的数字相加)】
- 【LeetCode-面试算法经典-Java实现】【130-Surrounded Regions(环绕区域)】
- 【LeetCode-面试算法经典-Java实现】【134-Gas Station(加油站问题)】