A.Phorni
题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Phorni
没做。。。
B.Arietta
题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Arietta
想到了网络流,所以每次暴力算出哪些点能被弹奏,就从这次弹奏向哪些点连容量为1的边
最后由s向所有力度连容量为该力度最多能被弹多少次的边,由每个节点连t容量为1的边
求最大流,得到了暴力分30分。正解还不会
代码:
1 const inf=maxlongint;maxn=10000+100;maxm=1000000; 2 type node=record 3 go,next,v:longint; 4 end; 5 var tot,i,n,m,maxflow,l,r,s,t,x,y,tot2:longint; 6 h,head,head2,q,cur,v:array[0..maxn] of longint; 7 e:array[0..maxm] of node; 8 e2:array[0..maxn] of node; 9 function min(x,y:longint):longint; 10 begin 11 if x<y then exit(x) else exit(y); 12 end; 13 procedure ins(x,y,z:longint); 14 begin 15 inc(tot); 16 e[tot].go:=y;e[tot].v:=z;e[tot].next:=head[x];head[x]:=tot; 17 end; 18 procedure insert(x,y,z:longint); 19 begin 20 ins(x,y,z);ins(y,x,0); 21 end; 22 function bfs:boolean; 23 var i,x,y:longint; 24 begin 25 fillchar(h,sizeof(h),0); 26 l:=0;r:=1;q[1]:=s;h[s]:=1; 27 while l<r do 28 begin 29 inc(l); 30 x:=q[l]; 31 i:=head[x]; 32 while i<>0 do 33 begin 34 y:=e[i].go; 35 if (e[i].v<>0) and (h[y]=0) then 36 begin 37 h[y]:=h[x]+1; 38 inc(r);q[r]:=y; 39 end; 40 i:=e[i].next; 41 end; 42 end; 43 exit (h[t]<>0); 44 end; 45 function dfs(x,f:longint):longint; 46 var i,y,used,tmp:longint; 47 begin 48 if x=t then exit(f); 49 used:=0; 50 i:=cur[x]; 51 while i<>0 do 52 begin 53 y:=e[i].go; 54 if (h[y]=h[x]+1) and (e[i].v<>0) then 55 begin 56 tmp:=dfs(y,min(e[i].v,f-used)); 57 dec(e[i].v,tmp);if e[i].v<>0 then cur[x]:=i; 58 inc(e[i xor 1].v,tmp); 59 inc(used,tmp); 60 if used=f then exit(f); 61 end; 62 i:=e[i].next; 63 end; 64 if used=0 then h[x]:=-1; 65 exit(used); 66 end; 67 procedure dinic; 68 var i:longint; 69 begin 70 while bfs do 71 begin 72 for i:=s to t do cur[i]:=head[i]; 73 inc(maxflow,dfs(s,inf)); 74 end; 75 end; 76 procedure insert2(x,y:longint); 77 begin 78 inc(tot2); 79 e2[tot2].go:=y;e2[tot2].next:=head2[x];head2[x]:=tot2; 80 end; 81 procedure init; 82 begin 83 tot:=1; 84 readln(n,m); 85 for i:=2 to n do begin read(x);insert2(x,i);end;readln; 86 for i:=1 to n do read(v[i]);readln; 87 end; 88 procedure dfss(x:longint); 89 var j,y:longint; 90 begin 91 if (v[x]>=l) and (v[x]<=r) then insert(i,x,1); 92 j:=head2[x]; 93 while j<>0 do 94 begin 95 y:=e2[j].go; 96 dfss(y); 97 j:=e2[j].next; 98 end; 99 end; 100 101 procedure main; 102 begin 103 s:=0;t:=n+m+1; 104 for i:=1 to n do insert(i,t,1); 105 for i:=n+1 to n+m do 106 begin 107 readln(l,r,x,y); 108 insert(s,i,y); 109 dfss(x); 110 end; 111 maxflow:=0; 112 dinic; 113 writeln(maxflow); 114 end; 115 116 begin 117 init; 118 main; 119 end.