标签:sam int however next log sts i++ 添加 day
#include <stdio.h> #include <algorithm> #include <math.h> #include <string.h> #include <vector> #include <queue> #include <stack> #include <iostream> #define pi acos(-1.0) #define INF 0x3f3f3f3f using namespace std; #define ll long long const int maxm=251000+7; const int maxn=1010; struct edge { int t,w,f,next; }e[2*maxm]; int dis[maxn]; int head[maxn],cnt; void add_edge(int u,int v,int f) { e[cnt].t=v,e[cnt].f=f; e[cnt].next=head[u]; head[u]=cnt++; e[cnt].t=u,e[cnt].f=0; e[cnt].next=head[v]; head[v]=cnt++; } void init() { memset(head,-1,sizeof head); cnt=0; } int bfs(int t) { memset(dis,-1,sizeof dis); queue<int> q; dis[0]=1; q.push(0); while(!q.empty()) { int k=q.front();q.pop(); for(int i=head[k];i!=-1;i=e[i].next) { int v=e[i].t; if(e[i].f&&dis[v]==-1) { dis[v]=dis[k]+1; if(v==t) return 1; q.push(v); } } } return dis[t]!=-1; } int dfs(int s,int t,int f) { if(s==t||!f) return f; int r=0; for (int i=head[s]; i!=-1; i=e[i].next) { int v=e[i].t; if(dis[v]==dis[s]+1&&e[i].f) { int d=dfs(v,t,min(f,e[i].f)); if(d>0) { e[i].f-=d; e[i^1].f+=d; r+=d; f-=d; if(!f) break; } } } if(!r) dis[s]=INF; return r; } int main() { freopen("C:\\Users\\Administrator\\Desktop\\a.txt","r",stdin); //ios::sync_with_stdio(false); //freopen("C:\\Users\\Administrator\\Desktop\\b.txt","w",stdout); int T,n,m,Case=0; scanf("%d",&T); while(T--) { int st=INF,et=0,sump=0; scanf("%d%d",&n,&m); init(); for(int i=1;i<=n;i++) { int p,s,e; scanf("%d%d%d",&p,&s,&e); add_edge(0,i,p); sump+=p; st=min(st,s); et=max(et,e); for(int j=s;j<=e;j++) add_edge(i,n+j,1); } int t=n+et-st+2; //cout<<n+st<<" "<<n+et<<" "<<t<<endl; for(int i=st+n;i<=et+n;i++) add_edge(i,t,m); int ans=0,res; while(bfs(t)) { res=dfs(0,t,INF); ans+=res; } //printf("%d\n",ans); printf("Case %d: ",++Case); if(ans==sump) puts("Yes"); else puts("No"); printf("\n"); } return 0; }
标签:sam int however next log sts i++ 添加 day
原文地址:http://www.cnblogs.com/MeowMeowMeow/p/7512457.html