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. 无线渗透测试之wifi密码破解

    [声明]:本文仅供个人学习使用,请勿违法破解他人wifi 测试工具: 1.CDlinux启动盘:(请参照https://my.oschina.net/u/3112136/blog/800713) 2. ...

  2. Java8之Lambda表达式基础

    Java 8中,将会提供对lambda的支持,函数式编程FP(Functional Programming)将会得到很好地支持,而函数式编程的一个重要特点就是适合并行运算. λ:希腊字母表中排序第十一 ...

  3. [用CDQ分治解决区间加&区间求和]【习作】

    [前言] 作为一个什么数据结构都不会只会CDQ分治和分块的蒟蒻,面对区间加&区间求和这么难的问题,怎么可能会写线段树呢 于是,用CDQ分治解决区间加&区间求和这篇习作应运而生 [Par ...

  4. CodeChef Little Elephant and Movies [DP 排列]

    https://www.codechef.com/FEB14/problems/LEMOVIE 题意: 对于一个序列,定义其“激动值”为序列中严格大于前面所有数的元素的个数.给定n个数p1;,p2.. ...

  5. python实现时间o(1)的最小栈

    这是毕业校招二面时遇到的手写编程题,当时刚刚开始学习python,整个栈写下来也是费了不少时间.毕竟语言只是工具,只要想清楚实现,使用任何语言都能快速的写出来. 何为最小栈?栈最基础的操作是压栈(pu ...

  6. 《Discuz安装时候出现乱码 -- 问题解决方法》

    自我安装discuz时出现安装界面乱码的情况,跟链接所说一样,经过原作的分享,加上我自己的实验,明白了,什么时候修改/usr/local/php/etc/php.ini里面的default_chars ...

  7. Scrapy-简单介绍

    Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 其最初是为了 页面抓取 (更确切来说, 网络抓取 )所设计的, ...

  8. Selenium常用方法及函数、txt参数化

    常用方法及函数: 1.表单的提交方法:submit解释:查找到表单(from)直接调用submit即可实例:driver.find_element_by_id("form1").s ...

  9. yml 文件操作方法

    文件读取方法示例: import yaml fr = open('yml_file_address', 'r',encoding='utf-8') data = yaml.load(fr) print ...

  10. Spring Data与elasticsearch版本对应关系