ZOJ - 3261-Connections in Galaxy War(反向并查集)

题目链接

题意:有n个恒星,每个行星有个攻击力,m个行星之间的道路,q次操作,query:询问和a行星在同一个并查集中攻击力最大的行星编号,相同输出小的,没有输出-1,destory:将a行星和b行星之间联系删除,也就是说a行星到b行星之间的路径不存在了,但是仍可通过其他行星使得其二在同一个并查集中。

思路:反向并查集,先把所有的关系存下来,将m条路径除去被destory的以外建立并查集,然后从最后一个询问开始反向操作,遇到destory将道路重新加回并查集中,因为对于该条destory上面的询问来说这条路径并没有被destory,所以反向操作。

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> 
#include <map>
// #include<unordered_map>   
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>
using namespace std;
#define ll long long
#define INF 0x3f3f3f
const int N = 1e5+10;
int n, m, q;
int att[N], f[N], ans[N];
map<pair<int,int>,int>mp;
struct node
{
   
	int u, v, statu;
}e[N];
struct nnode
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值