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. BZOJ 4259: 残缺的字符串 [FFT]

    4259: 残缺的字符串 题意:s,t,星号任意字符,匹配方案数 和上题一样 多乘上一个\(a_{j+i}\)就行了 #include <iostream> #include <cs ...

  2. JS 特殊字符的验证的问题

    个人的JS 的收集方便下次的使用做百度查询: 1. 特殊字符的验证: var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].&l ...

  3. Windows实用快捷键

    1 返回上一级目录:Backspace 2 复制当前窗口:Ctr + N 3 在当前文件目录中选定首个文件(夹):Space 4  切换窗口:Alt + Tab 5 当前浏览器Tab页倒退或前进历史页 ...

  4. 在CentOS下安装crontab服务

    1. 确认crontab是否安装: 执行 crontab 命令如果报 command not found,就表明没有安装 2. 安装 crontab 执行 yum install -y vixie-c ...

  5. 使用CentOS Linux Bridge搭建Vxlan环境

    一. 基础环境使用VmWare虚拟两台Linux机器.CentOS 7,Linux内核如下:4.5.3-1.el7.elrepo.x86_64如果内核版本太低,是不支持VxLan的.可以使用一下命令进 ...

  6. Nginx调用远程php-fpm

    在Nginx服务器的情况下,当我们输入 http://localhost:8080/index.php回车的时候 浏览器会将请求发送给Nginx,Nginx会根据我们所配置的以.php结尾的PHP的文 ...

  7. 【实用】需要收藏备用的JQuery代码片段

    1 元素屏幕居中 jQuery.fn.center = function () { this.css("position","absolute"); this. ...

  8. MySql 性能调优策略

    本主题调优针对于my.cnf配置来做详细的参数说明 示例配置如下: #cat my.cnf # MySQL client library initialization. [client] port = ...

  9. 抛砖引玉之~sftp

    跨平台系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#linux XFtp用惯了,没有它就不行了?Linux就不能文件传输了? 答案肯定是~No ...

  10. Nginx和php是怎么通信的?

    先来看一下搭建好PHP运行环境的Nginx配置文件. 非常重要的就是 fastcgi_pass 指令了,这个指令用于指定 fpm 进程监听的地址,Nginx 会把所有的 php 请求翻译成 fastc ...