hdu5923 Prediction
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的更多相关文章
- 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)
Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...
- scikit-learn使用笔记与sign prediction简单小结
经Edwin Chen的推荐,认识了scikit-learn这个非常强大的python机器学习工具包.这个帖子作为笔记.(其实都没有笔记的意义,因为他家文档做的太好了,不过还是为自己记记吧,为以后节省 ...
- 【转载】Chaotic Time-Series Prediction
原文地址:https://cn.mathworks.com/help/fuzzy/examples/chaotic-time-series-prediction.html?requestedDomai ...
- (转)LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION
LSTM NEURAL NETWORK FOR TIME SERIES PREDICTION Wed 21st Dec 2016 Neural Networks these days are th ...
- 【软件分析与挖掘】Multiple kernel ensemble learning for software defect prediction
摘要: 利用软件中的历史缺陷数据来建立分类器,进行软件缺陷的检测. 多核学习(Multiple kernel learning):把历史缺陷数据映射到高维特征空间,使得数据能够更好地表达: 集成学习( ...
- FJNU 1155 Fat Brother’s prediction(胖哥的预言)
FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS Memory Limit: 257792K [Description] [ ...
- MATLAB时间序列预测Prediction of time series with NAR neural network
具体请参考:http://lab.fs.uni-lj.si/lasin/wp/IMIT_files/neural/nn05_narnet/ 神经网络预测时间序列数据,有三种模型, 这里是给出的是第二种 ...
- 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 ...
- Intra Luma Prediction
在宏块的帧内预测过程中,有四种宏块类型:I_4x4,I_8x8,I16x16,I_PCM.他们都需要在相邻块做去块滤波之前进行帧内预测. 亮度帧内预测的总体流程 1-4获取当前block的帧内预测模式 ...
随机推荐
- SpringMVC源码情操陶冶-DispatcherServlet
本文对springmvc核心类DispatcherServlet作下简单的向导,方便博主与读者查阅 DispatcherServlet-继承关系 分析DispatcherServlet的继承关系以及主 ...
- 洛谷 [P2296] 寻找道路
反向BFS预处理,求出所有符合题意的点,再正向BFS,(注意对于边权恒为一的点,BFS,比SPFA高效) 输入时n与m分清 #include <iostream> #include < ...
- 51NOD 1220 约数之和 [杜教筛]
1220 约数之和 题意:求\(\sum_{i=1}^n \sum_{j=1}^n \sigma_1(ij)\) \[ \sigma_0(ij) = \sum_{x\mid i}\sum_{y\mi ...
- ES6,数组遍历
ES6提供了entries(),keys(),values()方法返回数组的遍历器,对于遍历器(Iterator)可以使用for...of进行便利,也可是使用entries()返回的遍历器Iterat ...
- python写一个md5解密器
前言: md5解密,百度了一下发现教程不是很多也不详细. 这个图都没一张...跳转地址:点我 0x01 windows环境,kali也可以啊 burpsuite requests模块 bs4模块 0x ...
- 关于@Override
首先,来了解一下“重载”和“覆写”的区别: 重载: (1)方法重载是让类以统一的方式处理不同类型数据的一种手段.多个同名函数同时存在,具有不同的参数个数/类型.重载Overloading是一个类中多态 ...
- DataGrid 拖动 附加属性类
项目需要实现一个DataGrid拖动排序,于是参考网上一些资源然后,修改了下实现了一个附加属性类,如下 使用方法 <DataGrid x:Name="shareGrid" t ...
- linux scp远程拷贝文件及文件夹
[http://www.jb51.net/LINUXjishu/73131.html] 1.拷贝本机/home/administrator/test整个目录至远程主机192.168.1.100的/ro ...
- [业界良心系列] OI资料分享
正式退役辣....混吃等死了这么久以后....终于也是必然的结果吧.... 分享一些资料: 链接:http://pan.baidu.com/s/1c1SRFmo 密码:bcfc 有一些资料有版权, 如 ...
- 【学习笔记】Hibernate HQL连接查询和数据批处理 (Y2-1-7)
HQL连接查询 和SQL查询一样 hql也支持各种链接查询 如内连接 外连接 具体如下 左外连接 left (outer) join 迫切左外连接 left (outer) join fetch 右外 ...