jxt的思路 先膜一发
先处理 T这棵树上每个点到祖先这条链的点所生成的并查集
每个点的并查集都得分开来存
这个dfs做就好了
最后询问的时候 将k 个点的并查集合并就是这个询问的连通图
易得答案

#include<bits/stdc++.h>
using namespace std;
#define sz(X) ((int)X.size()) int n,m,q;
vector<int> mp[10005];
int f[10005][505];
int find(int x, int ty){return x==f[ty][x]?x:(f[ty][x]=find(f[ty][x], ty));}
int E[10005][2];
int so[505];
int cn[505];
void dfs(int x, int pre) {
for(int i = 1; i <= n; ++i) f[x][i] = f[pre][i];
int fx= find(E[x][0],x); int fy = find(E[x][1],x);
if(fx != fy) f[x][fx] = fy; for(int i = 0; i < sz(mp[x]); ++i) {
int y = mp[x][i];
dfs(y,x);
}
}
int main(){
int _; scanf("%d",&_);
for(int cas=1;cas<=_;cas++) {
memset(cn,0,sizeof(cn));
scanf("%d %d",&n,&m);
for(int i = 1; i <= n; ++i) f[1][i] = i;
for(int i = 1; i <= m; ++i) mp[i].clear();
for(int i = 2; i <= m; ++i) {
int a; scanf("%d",&a);
mp[a].push_back(i);
}
for(int i = 1; i <= m; ++i) {
scanf("%d %d",&E[i][0],&E[i][1]);
}
dfs(1,1); scanf("%d",&q);
printf("Case #%d:\n",cas);
for(int i = 1; i <= q; ++i) {
for(int j = 1; j <= n; ++j) f[0][j] = j;
int k; scanf("%d",&k);
for(int j = 0; j < k; ++j) {
int a; scanf("%d",&a);
for(int l = 1; l <= n; l++) {
int t1 = find(l,a);
if(t1 != l) {
int x = find(t1,0); int y = find(l,0);
if(x != y) f[0][x] = y;
}
}
} int ans = 0;
for(int j = 1; j <= n; ++j) {
int x = find(j,0);
if(cn[x] < i) ans ++;
cn[x] = i;
}
printf("%d\n",ans);
}
}
return 0;
}

hdu5923 Prediction的更多相关文章

  1. 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)

    Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...

  2. scikit-learn使用笔记与sign prediction简单小结

    经Edwin Chen的推荐,认识了scikit-learn这个非常强大的python机器学习工具包.这个帖子作为笔记.(其实都没有笔记的意义,因为他家文档做的太好了,不过还是为自己记记吧,为以后节省 ...

  3. 【转载】Chaotic Time-Series Prediction

    原文地址:https://cn.mathworks.com/help/fuzzy/examples/chaotic-time-series-prediction.html?requestedDomai ...

  4. (转)LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION

    LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION Wed 21st Dec 2016   Neural Networks these days are th ...

  5. 【软件分析与挖掘】Multiple kernel ensemble learning for software defect prediction

    摘要: 利用软件中的历史缺陷数据来建立分类器,进行软件缺陷的检测. 多核学习(Multiple kernel learning):把历史缺陷数据映射到高维特征空间,使得数据能够更好地表达: 集成学习( ...

  6. FJNU 1155 Fat Brother’s prediction(胖哥的预言)

    FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  7. MATLAB时间序列预测Prediction of time series with NAR neural network

    具体请参考:http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn05_narnet/ 神经网络预测时间序列数据,有三种模型, 这里是给出的是第二种 ...

  8. Kaggle Bike Sharing Demand Prediction – How I got in top 5 percentile of participants?

    Kaggle Bike Sharing Demand Prediction – How I got in top 5 percentile of participants? Introduction ...

  9. Intra Luma Prediction

    在宏块的帧内预测过程中,有四种宏块类型:I_4x4,I_8x8,I16x16,I_PCM.他们都需要在相邻块做去块滤波之前进行帧内预测. 亮度帧内预测的总体流程 1-4获取当前block的帧内预测模式 ...

随机推荐

  1. 洛谷 [P4011] 孤岛营救问题

    状压+BFS 通过观察数据范围可知,我们应该状压钥匙种类,直接BFS即可 注意,一个点处可能不知有一把钥匙 #include <iostream> #include <cstdio& ...

  2. BZOJ 2463: [中山市选2009]谁能赢呢?[智慧]

    明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之前不能被访问过.谁不能移 ...

  3. HDU 3595 GG and MM [Every-SG]

    传送门 题意: 两个数$x,y$,一个人的决策为让大数减去小数的任意倍数(结果不能为负),出现0的人胜 一堆这样的游戏同时玩 Every-SG 游戏规定,对于还没有结束的单一游戏,游戏者必须对该游戏进 ...

  4. BZOJ 3514: Codechef MARCH14 GERALD07加强版 [LCT 主席树 kruskal]

    3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec  Memory Limit: 256 MBSubmit: 1312  Solved: 501 ...

  5. element ui 1.4 升级到 2.0.11

    公司的框架 选取的是 花裤衩大神开源的 基于 element ui + Vue 的后台管理项目, 项目源码就不公开了,记录 分享下 步骤 1. 卸载 element ui 1.4的依赖包 2. 卸载完 ...

  6. 如何使用 Bootstrap 搭建更合理的 HTML 结构

    前言 Bootstrap 的成功不仅在于其简单易用,更在于其样式的规范性以及 HTML 结构的合理性.但是很多人在使用 Bootstrap 时只是依照文档盲目的复制黏贴,并没有仔细考虑每个类的用处,也 ...

  7. typeof面试题解答

    面试题 alert(typeof null); // object alert(typeof undefined); // undefined alert(typeof NaN); // number ...

  8. Vue中结合Flask与Node.JS的异步加载功能实现文章的分页效果

    你好!欢迎阅读我的博文,你可以跳转到我的个人博客网站,会有更好的排版效果和功能. 此外,本篇博文为本人Pushy原创,如需转载请注明出处:http://blog.pushy.site/posts/15 ...

  9. The SSL certificate used to load resources from xxx will be distrusted in M70.

    今天在浏览网站的时候遇到如下报警信息: The SSL certificate used to load resources from https://xxx.com will be distrust ...

  10. CentOS 7 安装Maven

    Maven的下载地址是:http://maven.apache.org/download.cgi 安装Maven非常简单,只需要将下载的压缩文件解压就可以了. cd /data wget http:/ ...