题意:有N个星球,每个星球有自己的武力值。星球之间有M条无向边,连通的两个点可以相互呼叫支援,前提是对方的武力值要大于自己。当武力值最大的伙伴有多个时,选择编号最小的。有Q次操作,destroy为切断连接两点的边,query为查询某星球能不能向它人呼叫支援。

还是需要离线逆向并查集求解。思路和HDU 4496很相似,但是此处不一定是把所有边都删去,所以需要删边的情况建立出最终的状态。因为N可以到1e4,所以可以用map嵌套map的方式记录过程中被删去的边,最后再根据删除情况建立状态。

在合并时需要维护自己能够申请到的支援的武力最大值,以及其编号。

 #include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
const int maxn = 2e4+;
const int INF= 0x3f3f3f3f;
struct Edge{
int u,v;
}E[maxn];
struct Query{
int op,a,b;
LL ans;
}p[maxn*];
LL w[maxn];
LL dist[maxn];
int fa[maxn];
int maxid[maxn];
inline int Find(int x) {return fa[x]==x ?x: fa[x]=Find(fa[x]);}
//void init(int N){ for(int i=0;i<N;++i) fa[i]=i,dist[i]=w[i],maxid[i]=i;}
void Union(int a,int b){
a = Find(a),b = Find(b);
if(a!=b){
fa[a] = b;
if(dist[b]<dist[a] || dist[b]==dist[a] && maxid[b]>maxid[a]){
dist[b]=dist[a];
maxid[b]= maxid[a];
}
}
} map<int,map<int,int> > tag; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int T,N,M,Q,u,v,tmp,K,cas=;
char op[];
int mk = ;
while(scanf("%d",&N)==){
if(mk) printf("\n");
mk = ;
for(int i=;i<N;++i) {
scanf("%lld",&w[i]);
fa[i]=maxid[i]=i;
dist[i]=w[i];
}
tag.clear();
scanf("%d",&M);
for(int i=;i<=M;++i){
scanf("%d%d",&u,&v);
E[i].u =u , E[i].v=v;
}
scanf("%d",&Q);
for(int i=;i<=Q;++i){
scanf("%s%d",op,&p[i].a);
if(op[]=='d') {
p[i].op=;
scanf("%d",&p[i].b);
tag[p[i].a][p[i].b]=tag[p[i].b][p[i].a]=; //被删边的标记
}
else p[i].op = ; //0删边,1查询
}
//因为并不是把边全删完,建立最终状态
for(int i=;i<=M;++i){
if(tag[E[i].u][E[i].v]) continue; //这条边不在
else Union(E[i].u,E[i].v);
} for(int i=Q;i>=;--i){
if(!p[i].op) Union(p[i].a,p[i].b);
else{
u = Find(p[i].a);
if(dist[u]>w[p[i].a]) p[i].ans=maxid[u];
else p[i].ans= -;
}
}
for(int i=;i<=Q;++i){
if(p[i].op) printf("%lld\n",p[i].ans);
}
}
return ;
}

ZOJ 3261 Connections in Galaxy War (逆向+带权并查集)的更多相关文章

  1. ZOJ 3261 Connections in Galaxy War(逆向并查集)

    参考链接: http://www.cppblog.com/yuan1028/archive/2011/02/13/139990.html http://blog.csdn.net/roney_win/ ...

  2. zoj 3261 Connections in Galaxy War

    点击打开链接zoj 3261 思路: 带权并查集 分析: 1 题目说的是有n个星球0~n-1,每个星球都有一个战斗值.n个星球之间有一些联系,并且n个星球之间会有互相伤害 2 根本没有思路的题,看了网 ...

  3. 洛谷 P1197 BZOJ 1015 [JSOI2008]星球大战 (ZOJ 3261 Connections in Galaxy War)

    这两道题长得差不多,都有分裂集合的操作,都是先将所有操作离线,然后从最后一步开始倒着模拟,这样一来,分裂就变成合并,也就是从打击以后最终的零散状态,一步步合并,回到最开始所有星球都被连为一个整体的状态 ...

  4. zoj 3261 Connections in Galaxy War(并查集逆向加边)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3261 题意:有很多颗星球,各自有武力值,星球间有一些联系通道,现 ...

  5. ZOJ 3261 - Connections in Galaxy War ,并查集删边

    In order to strengthen the defense ability, many stars in galaxy allied together and built many bidi ...

  6. 题解报告:zoj 3261 Connections in Galaxy War(离线并查集)

    Description In order to strengthen the defense ability, many stars in galaxy allied together and bui ...

  7. ZOJ - 3261 Connections in Galaxy War(并查集删边)

    https://cn.vjudge.net/problem/ZOJ-3261 题意 银河系各大星球之间有不同的能量值, 并且他们之间互相有通道连接起来,可以用来传递信息,这样一旦有星球被怪兽攻击,便可 ...

  8. 洛谷OJ P1196 银河英雄传说(带权并查集)

    题目描述 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦 创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰山 ...

  9. Lightoj1009 Back to Underworld(带权并查集)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Back to Underworld Time Limit:4000MS      ...

随机推荐

  1. 几款 ping tcping 工具总结

    本文转载至:http://www.cnblogs.com/kerrycode/p/8092942.html ping 命令以前是一个很好用并且常用的网络测试工具,它是基于 ICMP 协议,但是出于网络 ...

  2. 第二百二十九节,jQuery EasyUI,后台管理界面---后台登录

    jQuery EasyUI,后台管理界面---后台登录 登录原理图 一,login.php,登录界面 <!DOCTYPE html> <html> <head> & ...

  3. Sql server 打不开了,无法识别的配置节 system.serviceModel 解决方案

    异常描述: System.Configuration.ConfigurationErrorsException: 配置系统未能初始化 ---> System.Configuration.Conf ...

  4. 机器学习之svm---cv wiki svm

    http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/ml/introduction_to_svm/introduction_to_s ...

  5. (转)Unity笔记之编辑器(BeginToggleGroup、BoundsField、ColorField) ...

    1. BeginToggleGroup() BeginToggleGroup函数是定义了一个控制范围,可以控制该范围中的GUI是否启用,看下演示代码: [code]csharpcode: using ...

  6. linux软件的安装和卸载

    http://blog.chinaunix.net/uid-25572546-id-1995028.html

  7. php 使用curl 进行简单模拟提交表单

    //初始化curl $ch = curl_init(); $url = 'xxx'; $option = [ CURLOPT_URL => $url, CURLOPT_HEADER => ...

  8. freemarker的${!}

    ${sss!} <#--没有定义这个变量,默认值是空字符串! --> ...................................... 转自:https://blog.csdn ...

  9. 常用的mysql语句

    为了方便学习mysql,把接触到的sql收集一下,忘记的时候可以查询一下. 连接mysql数据库: mysql -u 用户名 -p 输入密码. 创建数据库: create database 数据库名; ...

  10. About AcitveDirectory EventLog

    参考微软文档整理的常用EVENTID: Account Logon Account Management Policy Change Event ID Event message 分類 類別 4670 ...