同[ZJOI2012]网络,把每个点拆成C个点然后用LCT维护。

#include<cstdio>
#include<map>
#define P make_pair
#define N 800002
using namespace std;
int f[N],d[8002][102],son[N][2],a[N],n;bool rev[N];
map<int,int>co[N];
inline int id(int x,int c){return x+n*c;}
inline void swap(int&a,int&b){int c=a;a=b;b=c;}
inline bool isroot(int x){return !f[x]||son[f[x]][0]!=x&&son[f[x]][1]!=x;}
inline void reverse(int x){swap(son[x][0],son[x][1]),rev[x]^=1;}
inline void pb(int x){if(rev[x])reverse(son[x][0]),reverse(son[x][1]),rev[x]=0;}
inline void rotate(int x){
int y=f[x],w=(son[y][1]==x);
son[y][w]=son[x][w^1];
if(son[x][w^1])f[son[x][w^1]]=y;
if(f[y]){
int z=f[y];
if(son[z][0]==y)son[z][0]=x;
if(son[z][1]==y)son[z][1]=x;
}
f[x]=f[y];son[x][w^1]=y;f[y]=x;
}
inline void splay(int x){
int s=1,i=x,y;a[1]=i;
while(!isroot(i))a[++s]=i=f[i];
while(s)pb(a[s--]);
while(!isroot(x)){
y=f[x];
if(!isroot(y)){if((son[f[y]][0]==y)^(son[y][0]==x))rotate(x);else rotate(y);}
rotate(x);
}
}
inline void access(int x){for(int y=0;x;y=x,x=f[x])splay(x),son[x][1]=y;}
inline int root(int x){access(x);splay(x);while(son[x][0])x=son[x][0];return x;}
inline void makeroot(int x){access(x);splay(x);reverse(x);}
inline void link(int x,int y){makeroot(x);f[x]=y;access(x);}
inline void cutf(int x){access(x);splay(x);f[son[x][0]]=0;son[x][0]=0;}
inline void cut(int x,int y){makeroot(x);cutf(y);}
inline void change(int x,int y,int c){
if(x>y)swap(x,y);
int c0=co[x][y];
if(!c0){puts("No such cable.");return;}
c0--;
if(c0==c){puts("Already owned.");return;}
if(d[x][c]==2||d[y][c]==2){puts("Forbidden: monopoly.");return;}
int x0=id(x,c0),y0=id(y,c0),x1=id(x,c),y1=id(y,c);
if(root(x1)==root(y1)){puts("Forbidden: redundant.");return;}
cut(x0,y0);link(x1,y1);
d[x][c0]--,d[y][c0]--;
d[x][c]++,d[y][c]++;
co[x][y]=c+1;
puts("Sold.");
}
inline void read(int&a){char ch;a=0;while(!(((ch=getchar())>='0')&&(ch<='9')));a*=10,a+=ch-'0';while(((ch=getchar())>='0')&&(ch<='9'))(a*=10)+=ch-'0';}
int m,c,k,x,y,u,v,w;
int main(){
read(n),read(m),read(c),read(k);
while(m--){
read(u),read(v),read(w);w--;if(u>v)swap(u,v);
co[u][v]=w+1;
x=id(u,w),y=id(v,w);
d[u][w]++,d[v][w]++;
link(x,y);
}
while(k--)read(u),read(v),read(w),change(u,v,w-1);
return 0;
}

  

BZOJ3651 : 网络通信的更多相关文章

  1. 【BZOJ3651】网络通信 LCT

    [BZOJ3651]网络通信 Description 有一个由M 条电缆连接的 N 个站点组成的网络.为了防止垄断,由 C 个公司控制所有的电缆,规定任何公司不能控制连接同一个站点的两条以上的电缆(可 ...

  2. 【BZOJ-3651&3081】网络通信&StrangeRegulations Link-Cut-Tree

    3651: 网络通信 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 90  Solved: 61[Submit][Status][Discuss] D ...

  3. ZeroMQ实例-使用ZMQ(ZeroMQ)进行局域网内网络通信

    本文内容摘要:1)安装zeromq.2)实例说明使用zmq进行网络间的消息发送和接收 首先在机器中安装zmq库 步骤如下: 1)下载zeromq的源代码,ZeroMQ的官方网址:http://zero ...

  4. 基础笔记12(socket,url网络通信)

    进一步深入socket 1.网络通信条件: .IP地址,可用主机名. .传输数据时将不用的应用程序通过数字标识区分开来,这种标识称为逻辑端口,也称端口.(0-65535端口,一般系统预留0-1024) ...

  5. Windows Store App 网络通信 HttpWebRequest

    如果希望更好地控制HTTP请求,可以使用System.Net类库中的HttpWebRequest类,该类对HTTP协议进行了完整的封装,并且提供了很多对HTTP协议中的 Header.Content和 ...

  6. socket网络通信

    1.socket通常也称作"套接字",用于描述IP地址和端口.在internet上的主机一般运行了多个服务软件,同时提供几种服务,每种服务都打开一个socket,并绑定到一个端口上 ...

  7. 20145316&20145229实验五:网络通信

    20145316&20145229实验五:网络通信 结对伙伴:20145316 博客链接:http://www.cnblogs.com/xxy745214935/p/6130897.html

  8. 网络通信之Socket与LocalSocket的比较

    Socket与LocalSocket都可以实现网络通信,两个有什么区别呢? LocalSocket其通信方式与Socket差不多,只是LocalSocket没有跨越网络边界. 于是,思考到一个问题:a ...

  9. Android 网络通信API的选择和实现实例

    Android开发网络通信一开始的时候使用的是AsyncTask封装HttpClient,没有使用原生的HttpURLConnection就跳到了Volley,随着OkHttp的流行又开始迁移到OkH ...

随机推荐

  1. jsp&servlet学习笔记

    1.路径引用问题 一个css.jsp.html.或者javascript文件从从一个工程复制到另一工程,如果引用的时候使用的时相对路径,看似没有错误,但是却一直引用不进来,这时候要使用绝对路径,这样才 ...

  2. C# 浅谈接口的优势

    总结了一下接口的小优势,可以便于新手理解为什么要用接口,用接口有什么好处. 1.接口的定义: 关键字:interface,接口名一般大写I开头,接口中定义方法,但是不实现方法 interface IB ...

  3. CVPR2015文章下载

    http://www.cv-foundation.org/openaccess/content_cvpr_2015/html/Liu_Real-Time_Part-Based_Visual_2015_ ...

  4. linux 回收站的添加

    在~下     .bashrc或者.bash_profile加入 mkdir -p ~/.trash     alias rm=trash       trash()     {      mv $@ ...

  5. centos安装redis及php-redis扩展

    centos安装redis及php-redis扩展  Linux, WEB 七162012 今天公司同事要求在测试机上安装redis,并且要求让php安装上redis的扩展,redis是一个key-v ...

  6. php中global与$GLOBALS的用法及区别

    php中global 与 $GLOBALS[""] 差别 原本觉得global和$GLOBALS除了写法不一样觉得,其他都一样,可是在实际利用中发现2者的差别还是很大的! 先看下面 ...

  7. Digit Counts

    Count the number of k's between 0 and n. k can be 0 - 9. Example if n = 12, k = 1 in [0, 1, 2, 3, 4, ...

  8. 利用WinHEX,重构狂牛加密视频1.0.0.1【只适合RIFF(AVI)】

    幸亏是视频部分没有进行加密 1.用 WinHEX 打开狂牛加密视频, 查找 [RIFF] 字符串 2.光标放在 RIFF的 [R]上面, 按 CTRL+SHIFT+END 3.把选择的块写入新文件 H ...

  9. HDU 2147 kiki's game(博弈)

    kiki's game Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit S ...

  10. Update startup files更新安装文件

    The service request did not complete because access to the service configuration manager was not gra ...