Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 4207 | Accepted: 1750 |
Description
Input
Output
Sample Input
2 2 08:00 10 11 9 16 08:07 9 16 10 11 2 08:00 10 11 9 16 08:06 9 16 10 11
Sample Output
1 2
Source
#include<cstdio> using namespace std; const int mm=555555; const int mn=1111; const int oo=1000000000; int node,src,dest,edge; int ver[mm],flow[mm],next[mm]; int head[mn],work[mn],dis[mn],q[mn]; int sx[mn],sy[mn],ex[mn],ey[mn],st[mn],et[mn]; inline int min(int a,int b) { return a<b?a:b; } inline void prepare(int _node,int _src,int _dest) { node=_node,src=_src,dest=_dest; for(int i=0;i<node;++i)head[i]=-1; edge=0; } inline void addedge(int u,int v,int c) { ver[edge]=v,flow[edge]=c,next[edge]=head[u],head[u]=edge++; ver[edge]=u,flow[edge]=0,next[edge]=head[v],head[v]=edge++; } bool Dinic_bfs() { int i,u,v,l,r=0; for(i=0;i<node;++i)dis[i]=-1; dis[q[r++]=src]=0; for(l=0;l<r;++l) for(i=head[u=q[l]];i>=0;i=next[i]) if(flow[i]&&dis[v=ver[i]]<0) { dis[q[r++]=v]=dis[u]+1; if(v==dest)return 1; } return 0; } int Dinic_dfs(int u,int exp) { if(u==dest)return exp; for(int &i=work[u],v,tmp;i>=0;i=next[i]) if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0) { flow[i]-=tmp; flow[i^1]+=tmp; return tmp; } return 0; } int Dinic_flow() { int i,ret=0,delta; while(Dinic_bfs()) { for(i=0;i<node;++i)work[i]=head[i]; while(delta=Dinic_dfs(src,oo))ret+=delta; } return ret; } inline int get(int a) { return a<0?-a:a; } int main() { int m,s,i,j,n,t; char c; scanf("%d",&t); while(t--) { scanf("%d",&n); prepare(n+n+2,0,n+n+1); for(i=1;i<=n;++i) { scanf("%d%c%d%d%d%d%d",&m,&c,&s,&sx[i],&sy[i],&ex[i],&ey[i]); et[i]=(st[i]=m*60+s)+get(sx[i]-ex[i])+get(sy[i]-ey[i]); } for(i=1;i<=n;++i) { addedge(src,i,1),addedge(i+n,dest,1); for(j=i+1;j<=n;++j) if(et[i]+get(ex[i]-sx[j])+get(ey[i]-sy[j])<st[j])addedge(i,n+j,1); } printf("%d\n",n-Dinic_flow()); } return 0; }