传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1046

试题描述:

WZJ又有一个问题想问问大家。WZJ用数据生成器生成了一个虚拟旅游区。这个旅游区由N个城市构成,标号从1到N,这些城市之间由M条双向道路连接。
其中每个城市有一个游乐场,游客可以花costi的钱数去城市i的游乐场玩,并获得happyi的高兴值,但对于一个游乐场,游客只能去玩至多一次。
因为虚拟旅游区的内存有限,有时候WZJ被迫在系统中删去一些边,当然WZJ可能忘记一些已被删去的边。
另外有些同学想来体验,WZJ会给他money的钱数,并把他送到城市x,他能通过未删除的道路去一些城市的游乐场玩。
下面请你帮助WZJ完成Q次操作,操作分两种:
1、0 y:虚拟旅游区的内存有限,WZJ被迫在系统中删去边y(不保证边y未被删去,这时你可以忽略这次指令)。
2、1 x money:又来了一个同学想来体验,WZJ给了他money的钱数,并把他送到城市x,问在最多花money的钱数能得到的最大高兴值。

输入:

输入第一行为三个正整数N,M,Q。
接下来N行每行为两个正整数costi,happyi。
再接下来M行每行为两个正整数ui,vi。
最后Q行每行为一个操作。

输出:

对于每个操作2,输出结果单占一行。

输入示例:

3 4 10
1 2
2 7 
1 4
1 2
2 3
1 3
1 1
1 1 2
1 1 1
0 1
1 1 1
1 1 2
0 2
1 1 2
0 2
0 3
1 1 3

输出示例:

7
4
4
7
6
2

其他说明:

1<=N<=10000, 1<=M,Q<=100000, 1<=ui,vi,x<=N, 1<=costi,money<=200, 1<=happyi<=100000,1<=y<=M

题解:时光倒流+背包dp

注意,加边的时候都搞成单向边了(,,• ₃ •,,)好神奇呀呀(。•ˇ‸ˇ•。)小健建就是NB呀呀呀(ㆀ˘・з・˘)

还有,结点要开2倍,我也不造为什么诺_( ゚Д゚)ノ

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#define REP(s, n) for(int i = s; i <= n; i ++)
#define RAP(s, n) for(int j = s; j <= n; j ++)
#define DE(i) e[POS(i)].del
#define POS(i) query[i].pos
#define V(i) query[i].v
#define ID(i) query[i].id
#define ANS(i) query[i].ans
#define COST(i) p[i].cost
#define HA(i) p[i].happy
using namespace std;
const int maxn = + ;
const int maxm = + ;
const int maxma = + ;
struct Point { int cost, happy; } p[maxn];
struct Edge {
int u, v, del;
Edge() { del = ; }
}e[maxm];
struct Tedge { int to, next; } adj[maxm];
struct Questions {
int pos, v, ans;
bool id;
Questions() { ans = ; }
}query[maxm];
int Q, n, m, dp[maxn][maxma], f[maxn], tar_num[maxn], fch[maxn];
int findset(int x){
return x == f[x] ? x : f[x] = findset(f[x]);
}
int ms = ;
void AddEdge(int from, int to){
adj[ms] = (Tedge) { to, fch[from] };
fch[from] = ms ++;
return ;
}
int que[maxn], tot;
void dfs(int x){
que[++ tot] = x;
for(int i = fch[x]; i; i = adj[i].next) dfs(adj[i].to);
return ;
}
void merge(int u, int v){
int f1 = findset(u), f2 = findset(v);
if(f1 == f2) return ;
if(tar_num[f1] > tar_num[f2]) swap(f1, f2);
tar_num[f2] += tar_num[f1]; tar_num[f1] = ; f[f1] = f2;
tot = ; dfs(f1); AddEdge(f2, f1);
REP(, tot){
int v = p[que[i]].cost, w = p[que[i]].happy;
for(int j = ; j >= v; j --) dp[f2][j] = max(dp[f2][j], dp[f2][j - v] + w);
}
return ;
}
void read(int &x){
x = ; int sig = ; char ch = getchar();
while(!isdigit(ch)) { if(ch == '-') sig = -; ch = getchar(); }
while(isdigit(ch)) x = * x + ch - '', ch = getchar();
x *= sig; return ;
}
void init(){
read(n), read(m), read(Q); int temp;
REP(, n) f[i] = i, tar_num[i] = ;
REP(, n){
read(COST(i)); read(HA(i));
RAP(COST(i), ) dp[i][j] = HA(i);
}
REP(, m) read(e[i].u), read(e[i].v);
REP(, Q){
read(temp); ID(i) = temp;
if(!ID(i)) {
read(POS(i));
if(!DE(i)) DE(i) = i;
}
else read(POS(i)), read(V(i));
}
return ;
}
void work(){
REP(, m) if(!e[i].del) merge(e[i].u, e[i].v);
for(int i = Q; i; i --){
if(!ID(i) && DE(i) == i) merge(e[POS(i)].u, e[POS(i)].v);
else ANS(i) = dp[findset(POS(i))][V(i)];
}
return ;
}
void print(){
REP(, Q) if(ID(i)) printf("%d\n", ANS(i));
return ;
}
int main(){
init();
work();
print();
return ;
}

COJ 3016 WZJ的图论问题的更多相关文章

  1. COJ 0346 WZJ的旅行(二)更新动态树分治版本

    WZJ的旅行(二) 难度级别:D: 运行时间限制:3000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 时隔多日,WZJ又来到了幻想国旅行.幻想国由N个城市组成,由 ...

  2. COJ 0967 WZJ的数据结构(负三十三)

    WZJ的数据结构(负三十三) 难度级别:E: 运行时间限制:7000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 请你设计一个数据结构,完成以下功能: 给定一个大 ...

  3. COJ 0970 WZJ的数据结构(负三十)树分治

    WZJ的数据结构(负三十) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给你一棵N个点的无根树,点和边上均有权值.请你设计 ...

  4. COJ 0349 WZJ的旅行(五)

    WZJ的旅行(五) 难度级别:E: 运行时间限制:3000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 WZJ又要去旅行了T^T=0.幻想国由N个城市组成,由于道 ...

  5. COJ 0990 WZJ的数据结构(负十)

    WZJ的数据结构(负十) 难度级别:D: 运行时间限制:5000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给你一个N个节点的有根树,从1到N编号,根节点为1并给 ...

  6. COJ 1008 WZJ的数据结构(八) 树上操作

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=986 WZJ的数据结构(八) 难度级别:E: 运行时间限制:3000ms: ...

  7. COJ 1007 WZJ的数据结构(七) 树上操作

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=983 WZJ的数据结构(七) 难度级别:C: 运行时间限制:1000ms: ...

  8. COJ 0343 WZJ的公司(二)

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=313 试题描述: WZJ的公司放假了!为了保证假期期间公司的安全,WZJ决定 ...

  9. COJ 0985 WZJ的数据结构(负十五)(限定区域不同数)

    传送门:http://oj.cnuschool.org.cn/oj/home/addSolution.htm?problemID=955 试题描述: CHX有一个问题想问问大家.给你一个长度为N的数列 ...

随机推荐

  1. 一个IT男的创业感言

    2014年的一月 我和高中的一个同学開始人生的第一次创业.就写点第一次创业的经验吧! 创业的最初 须要心中大概有个规划 这个规划可能是非常粗糙的 但大的方向一定要有.详细就是你进入的行业 行业已经存在 ...

  2. [AngularJS] 5 simple ways to speed up your AngularJS application

    Nowdays, Single page apps are becoming increasingly popular among the fornt-end developers. It is th ...

  3. iOS工具种之16进制颜色转为UIColor

     #define DEFAULT_VOID_COLOR [UIColor whiteColor] + (UIColor *)colorWithHexString:(NSString *)stringT ...

  4. jdbc插入修改clob类型的两种方式

    方法一: Connection con = dbl.loadConnection(); strSql = "insert into table1(id,a) values (1,EMPTY_ ...

  5. Python之路,Day26-----暂无正在更新中

    Python之路,Day26-----暂无正在更新中

  6. p标签里面不能嵌套div

    先申明本人代码水平为零起点,刚开始学习前端,所以就是小白.不过大神也是小白变身的么,所以要专心码代码,潜心钻研,haha~ 今天练习了段代码,发现效果和自己想象的不一样: 想了一下估计是<p&g ...

  7. linq的一些用法总结

    获取列表数据. IList<Model> list = dao.getmx(Model, pageInfo);//获取数据列表 1.将列表中id一样的数据进行group by分组,并返回序 ...

  8. SpringMVC简单搭建与入门

    SpringMVC框架是spring框架的一个模块.springmvc和spring无需要通过中间整合层进行整合. 学习的时候,先了解一下流程至关重要,下面,简单介绍一下流程. 源码下载:http:/ ...

  9. 测试stopwatch频率

    测试stopwatch频率 using UnityEngine; using System.Collections; using System.Diagnostics; public class te ...

  10. 想追赶.Net的脚步?Java面前障碍重重

    待到Java 8面世之时 .Net的进度时钟恐怕已经又走过了两到五年——届时微软做出的调整将使二者差距进一步拉大. 就在几周之前,我详细介绍了Java 8中值得期待的几大主要功能.不过当时我并没有提到 ...