Portal: http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1046
Question Description:
Wzj another question to ask you. WZJ generates a virtual tourist area with a data generator. This tourist area is made up of N cities, marking from 1 to N, which are connected by M-two-way roads between these cities.
Each city has a playground, visitors can spend Costi money to play in the city I playground, and get Happyi's happy value, but for a playground, visitors can only play at most once.
Because the virtual tourist area has limited memory, sometimes WZJ is forced to delete some edges in the system, and of course wzj may forget some of the deleted edges.
Other students want to experience, WZJ will give him money, and send him to the city X, he can go through the road to some cities to play.
Below please help WZJ to complete the Q operation, the operation is divided into two kinds:
1, 0 y: Virtual tourist area of limited memory, WZJ forced in the system to delete the Edge Y (not guaranteed that the edge Y is not deleted, then you can ignore this command).
2, 1 x money: Another classmate to want to experience, Wzj gave him money, and sent him to the city X, asked in the maximum amount can get the maximum happiness value.
Input:
Enter the first behavior of three positive integer n,m,q.
The next n rows are two positive integer costi,happyi per behavior.
Then the M-line each behaves two positive integers ui,vi.
The last Q line is one operation per action.
Output:
For each operation 2, the output separate a row.
Input Example:
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
Output Example:
7
4
4
7
6
2
Other Notes:
1<=n<=10000, 1<=m,q<=100000, 1<=ui,vi,x<=n, 1<=costi,money<=200, 1<=happyi<=100000,1 <=y<=m
Puzzle: Time reversal + Backpack DP
Note that when adding the edge of the time are made into one-way side (,,?,,) Good magic ah ah (? @@facesymbol@@?) Kingjian is NB Ah ah (??? By??)
Also, the knot to open twice times, I also do not make why Connaught _ (? Д?)?
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7 #defineREP (S, n) for (int i = s; i <= n; i + +)8 #defineRAP (S, n) for (int j = s; J <= N; j + +)9 #defineDE (i) E[pos (i)].delTen #definePOS (i) query[i].pos One #defineV (i) query[i].v A #defineID (i) query[i].id - #defineANS (i) Query[i].ans - #defineCost (i) p[i].cost the #defineHA (i) p[i].happy - using namespacestd; - Const intMAXN =20000+1; - Const intMAXM =100000+1; + Const intMaxma = $+1; - structPoint {intCost , happy;} P[MAXN]; + structEdge { A intu, V, del; atEdge () {del =0; } - }E[MAXM]; - structTedge {intto, next;} ADJ[MAXM]; - structQuestions { - intPos, V, ans; - BOOLID; inQuestions () {ans =0; } - }QUERY[MAXM]; to intQ, N, M, Dp[maxn][maxma], F[MAXN], TAR_NUM[MAXN], FCH[MAXN]; + intFindset (intx) { - returnx = = F[x]? X:F[X] =Findset (f[x]); the } * intms =1; $ voidAddedge (int from,intTo ) {Panax NotoginsengADJ[MS] = (Tedge) {to, fch[ from] }; -fch[ from] = ms + +; the return ; + } A intQUE[MAXN], tot; the voidDfsintx) { +que[++ tot] =x; - for(inti = fch[x]; I i =adj[i].next) DFS (adj[i].to); $ return ; $ } - voidMergeintUintv) { - intF1 = Findset (u), F2 =Findset (v); the if(f1 = = F2)return ; - if(Tar_num[f1] >Tar_num[f2]) swap (f1, F2);WuyiTAR_NUM[F2] + = tar_num[f1]; TAR_NUM[F1] =0; F[F1] =F2; thetot =0; Dfs (F1); Addedge (F2, F1); -REP (1, tot) { Wu intv = p[que[i]].cost, w =P[que[i]].happy; - for(intj = $; J >= v; J--) dp[f2][j] = max (Dp[f2][j], dp[f2][j-v] +W); About } $ return ; - } - voidReadint&x) { -x =0;intsig =1;CharCH =GetChar (); A while(!isdigit (CH)) {if(ch = ='-') sig =-1; CH =GetChar ();} + while(IsDigit (ch)) x =Ten* x + CH-'0', ch =GetChar (); theX *= sig;return ; - } $ voidinit () { theRead (n), read (m), read (Q);inttemp; theREP (1, n) f[i] = i, tar_num[i] =1; theREP (1, N) { the Read (Cost (i)); Read (HA (i)); -RAP (Cost (i), $) Dp[i][j] =HA (i); in } theREP (1, M) read (E[I].U), read (E[I].V); theREP (1, Q) { AboutRead (temp); ID (i) =temp; the if(!ID (i)) { the Read (POS (i)); the if(!de (i)) DE (i) =i; + } - ElseRead (POS (i)), read (V (i )); the }Bayi return ; the } the voidWork () { -REP (1, m)if(!e[i].del) Merge (e[i].u, E[I].V); - for(inti = Q; I I--){ the if(!id (i) && DE (i) = =i) Merge (E[pos (i)].u, E[pos (i)].v); the ElseANS (i) =Dp[findset (POS (i))][v (i)]; the } the return ; - } the voidprint () { theREP (1, Q)if(ID (i)) printf ("%d\n", ANS (i)); the return ;94 } the intMain () { the init (); the Work ();98 print (); About return 0; -}
The problem of graph theory of coj 3016 WZJ