zjoi网络
map加LCT水一下就过了
# include <stdio.h>
# include <stdlib.h>
# include <iostream>
# include <algorithm>
# include <string.h>
# include <map>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
IL ll Read(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
return x * z;
}
const int MAXN(10010);
int n, m, C, K, w[MAXN], S[MAXN];
struct Edge{
int u, v;
IL bool operator <(RG Edge B) const{ return u == B.u ? v < B.v : u < B.u; }
};
map <Edge, int> M;
struct Tree{ int ch[2], rev, fa, max, cnt; } t[11][MAXN];
IL bool Son(RG int x){ return t[C][t[C][x].fa].ch[1] == x; }
IL bool Isroot(RG int x){ return t[C][t[C][x].fa].ch[0] != x && t[C][t[C][x].fa].ch[1] != x; }
IL void Update(RG int x){ t[C][x].max = max(w[x], max(t[C][t[C][x].ch[0]].max, t[C][t[C][x].ch[1]].max)); }
IL void Pushdown(RG int x){
if(!t[C][x].rev) return; t[C][x].rev = 0;
swap(t[C][x].ch[0], t[C][x].ch[1]);
t[C][t[C][x].ch[0]].rev ^= 1; t[C][t[C][x].ch[1]].rev ^= 1;
}
IL void Rot(RG int x){
RG int y = t[C][x].fa, z = t[C][y].fa, c = Son(x);
if(!Isroot(y)) t[C][z].ch[Son(y)] = x; t[C][x].fa = z;
t[C][y].ch[c] = t[C][x].ch[!c]; t[C][t[C][y].ch[c]].fa = y;
t[C][x].ch[!c] = y; t[C][y].fa = x;
Update(y);
}
IL void Splay(RG int x){
RG int top = 0; S[++top] = x;
for(RG int y = x; !Isroot(y); y = t[C][y].fa) S[++top] = t[C][y].fa;
while(top) Pushdown(S[top--]);
for(RG int y = t[C][x].fa; !Isroot(x); Rot(x), y = t[C][x].fa)
if(!Isroot(y)) Son(y) ^ Son(x) ? Rot(x) : Rot(y);
Update(x);
}
IL void Access(RG int x){ for(RG int y = 0; x; y = x, x = t[C][x].fa) Splay(x), t[C][x].ch[1] = y, Update(x); }
IL int Findroot(RG int x){ Access(x); Splay(x); while(t[C][x].ch[0]) x = t[C][x].ch[0]; return x; }
IL void Makeroot(RG int x){ Access(x); Splay(x); t[C][x].rev ^= 1; }
IL void Split(RG int x, RG int y){ Makeroot(x); Access(y); Splay(y); }
IL void Link(RG int x, RG int y){ t[C][x].cnt++; t[C][y].cnt++; Makeroot(x); t[C][x].fa = y; }
IL void Cut(RG int x, RG int y){ Split(x, y); t[C][x].cnt--; t[C][y].cnt--; t[C][x].fa = t[C][y].ch[0] = 0; }
IL int Query(RG int x, RG int y){ Split(x, y); return t[C][y].max; }
int main(RG int argc, RG char* argv[]){
n = Read(); m = Read(); C = Read(); K = Read(); RG int Col = C;
for(RG int i = 1; i <= n; i++) w[i] = Read();
for(RG int i = 1; i <= m; i++){
RG int u = Read(), v = Read(); C = Read() + 1;
M[(Edge){u, v}] = M[(Edge){v, u}] = C; Link(u, v);
}
while(K--){
RG int opt = Read(), x = Read(), y = Read(), z, zz;
if(!opt){ w[x] = y; for(C = 1; C <= Col; C++) Splay(x); }
else if(opt == 1){
z = Read() + 1; C = zz = M[(Edge){x, y}];
if(!C){ puts("No such edge."); continue; }
if(C == z){ puts("Success."); continue; }
if(t[z][x].cnt > 1 || t[z][y].cnt > 1){ puts("Error 1."); continue; }
C = z; if(Findroot(x) == Findroot(y)){ puts("Error 2."); continue; }
C = zz; Cut(x, y); C = z; Link(x, y); M[(Edge){x, y}] = M[(Edge){y, x}] = C; puts("Success.");
}
else{
C = x + 1; x = Read();
if(Findroot(x) != Findroot(y)) puts("-1");
else printf("%d\n", Query(x, y));
}
}
return 0;
}
zjoi网络的更多相关文章
- zjoi 网络
题解: 很显然会发现对于每种颜色分开处理这是一颗树 然后就是裸的lct 有个坑就是判断操作1 可能颜色改成跟原先一样的 代码: #include <bits/stdc++.h> using ...
- [ ZJOI 2010 ] 网络扩容
\(\\\) Description 给定一张有向图,每条边都有一个容量 \(C\) 和一个扩容费用 \(W\). 这里扩容费用是指将容量扩大 \(1\) 所需的费用.求: 在不扩容的情况下, \(1 ...
- [ZJOI 2012] 网络
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2816 [算法] 对每种颜色的边建一棵LCT , 维护联通性即可 时间复杂度 : O( ...
- BZOJ-1834 网络扩容 最小费用最大流+最大流+乱搞
1834: [ZJOI2010]network 网络扩容 Time Limit: 3 Sec Memory Limit: 64 MB Submit: 2269 Solved: 1136 [Submit ...
- ZJOI 2019 划水记
作为一个极其蒟蒻的OIer,虽然没有省选资格但还是去见见世面. ZJOI2019一试是在浙江省镇海中学.听名字就很霸气. 学习OI的最后一年,记录下一些事情,即使最终走到最后也一无所获,也是一段美好的 ...
- Angular2入门系列教程7-HTTP(一)-使用Angular2自带的http进行网络请求
上一篇:Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数 感觉这篇不是很好写,因为涉及到网络请求,如果采用真实的网络请求,这个例子大家拿到手估计还要自己写一个web ...
- Android请求网络共通类——Hi_博客 Android App 开发笔记
今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
- 网络原因导致 npm 软件包 node-sass / gulp-sass 安装失败的处理办法
如果你正在构建一个基于 gulp 的前端自动化开发环境,那么极有可能会用到 gulp-sass ,由于网络原因你可能会安装失败,因为安装过程中部分细节会到亚马逊云服务器上获取文件.本文主要讨论在不变更 ...
- Virtual Box配置CentOS7网络(图文教程)
之前很多次安装CentOS7虚拟机,每次配置网络在网上找教程,今天总结一下,全图文配置,方便以后查看. Virtual Box可选的网络接入方式包括: NAT 网络地址转换模式(NAT,Network ...
随机推荐
- java生产者与消费者模式
前言: 生产者和消费者模式是我们在学习多线程中很经典的一个模式,它主要分为生产者和消费者,分别是两个线程, 目录 一:生产者和消费者模式简介 二:生产者和消费者模式的实现 声明:本例来源于java经典 ...
- 05-Git
[Git] [安装git] $ yum install git #安装git $ ssh-keygen #遇到输入符直接回车 $ cat ~/.ssh/id_rsa.pub #将这里的信息添加 ...
- Redis 实践2-数据结构
alias redis-cli='/usr/local/redis/bin/redis-cli' vi .bashrc 编辑加入 alias redis-cli='/usr/local/redi ...
- hql语句中的select字句和from 字句
package com.imooc.model; import java.util.List; import java.util.Map; import org.hibernate.Query; im ...
- Egret学习笔记 (Egret打飞机-4.添加主角飞机和实现飞行效果)
今天继续写点击了开始之后,添加一个飞机到场景中,然后这个飞机的尾巴还在冒火的那种感觉 先拆解一下步骤 1.首先完成飞机容器的图片加载 2.然后把容器添加到场景中 3.然后实现动画 -首先,我们新建一个 ...
- CODE大全浅谈谷歌adsense与PIN码
我的博客:CODE大全:www.codedq.net:业余草:www.xttblog.com:爱分享:www.ndislwf.com或ifxvn.com. 近期由于校园招聘笔试和面试等诸多忙碌时间,博 ...
- C++ 中vector的使用方法(转)
原地址:http://blog.csdn.net/duan19920101/article/details/50617190/ 在c++中,vector是一个十分有用的容器. 作用:它能够像容器一样存 ...
- ActiveMq笔记3-AMQ高可用性理论
单点的ActiveMQ作为企业应用无法满足高可用和集群的需求,所以ActiveMQ提供了master-slave.broker cluster等多种部署方式,但通过分析多种部署方式之后我认为需要将两种 ...
- Zookeeper笔记1-CAP/BASE理论
分布式系统八大谬论: 1.网络相当可靠 2.延迟为0 3.传输带宽是无限的 4.网络相当安全. 5.拓扑结构不会改变 6.必须要有一名管理员 7.传输成本为0 8.网络同质化. 分布式最常出现的问题: ...
- 老机器安装Centos
512M内存,80G硬盘 ubuntu-server没有压力,但是因为很多平台只支持centos服务器linux系统 内存要超过1G默认才能用图形界面安装.装好之后即使256M内存都可以跑起来.lin ...