标签:
2 10 1 10 6 3 2 10 4 2 2 10 1 10 5 3 2 10 4 2
Yes No
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 2000; 4 const int INF = 0x3f3f3f3f; 5 struct arc{ 6 int to,flow,next; 7 arc(int x = 0,int y = 0,int z = -1){ 8 to = x; 9 flow = y; 10 next = z; 11 } 12 }e[1000000]; 13 struct Server{ 14 int s,n,e,t; 15 }SV[500]; 16 int d[maxn],head[maxn],p[maxn],cur[maxn],tot,S,T,n,m; 17 void add(int u,int v,int flow){ 18 e[tot] = arc(v,flow,head[u]); 19 head[u] = tot++; 20 e[tot] = arc(u,0,head[v]); 21 head[v] = tot++; 22 } 23 bool bfs(){ 24 queue<int>q; 25 memset(d,-1,sizeof d); 26 d[S] = 1; 27 q.push(S); 28 while(!q.empty()){ 29 int u = q.front(); 30 q.pop(); 31 for(int i = head[u]; ~i; i = e[i].next){ 32 if(e[i].flow && d[e[i].to] == -1){ 33 d[e[i].to] = d[u] + 1; 34 q.push(e[i].to); 35 } 36 } 37 } 38 return d[T] > -1; 39 } 40 int dfs(int u,int low){ 41 if(u == T) return low; 42 int tmp = 0,a; 43 for(int &i = cur[u]; ~i; i = e[i].next){ 44 if(e[i].flow && d[e[i].to] == d[u]+1 &&(a=dfs(e[i].to,min(low,e[i].flow)))){ 45 tmp += a; 46 low -= a; 47 e[i].flow -= a; 48 e[i^1].flow += a; 49 if(!low) break; 50 } 51 } 52 if(!tmp) d[u] = -1; 53 return tmp; 54 } 55 int dinic(){ 56 int ret = 0; 57 while(bfs()){ 58 memcpy(cur,head,sizeof head); 59 ret += dfs(S,INF); 60 } 61 return ret; 62 } 63 int main(){ 64 while(~scanf("%d%d",&n,&m)){ 65 memset(head,-1,sizeof head); 66 int cnt = 0; 67 for(int i = 1; i <= n; ++i){ 68 scanf("%d%d%d%d",&SV[i].s,&SV[i].n,&SV[i].e,&SV[i].t); 69 p[cnt++] = SV[i].s; 70 p[cnt++] = SV[i].e; 71 } 72 sort(p,p+cnt); 73 cnt = unique(p,p+cnt)-p; 74 int sum = S = tot = 0; 75 T = cnt+n+1; 76 for(int i = 1; i < cnt; ++i) add(i+n,T,m*(p[i] - p[i-1])); 77 for(int i = 1; i <= n; ++i){ 78 add(S,i,SV[i].n*SV[i].t); 79 sum += SV[i].n*SV[i].t; 80 for(int j = 1; j < cnt; ++j) 81 if(SV[i].s <= p[j-1] && SV[i].e >= p[j]) add(i,j+n,INF); 82 } 83 puts(dinic() == sum?"Yes":"No"); 84 } 85 return 0; 86 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4554354.html