Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴一份深搜代码#include<cstdio> #include<cstring> #include<iostream> #include<queue> #include<cmath> #include<map> #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) using namespace std; struct node { int y,l,next; }k[150005]; struct point{ int p,l,n; }sp[110]; int lm,head[30005],m,n; int vis[30005],sta[30005]; void init(){ lm=0; memset(head,-1,sizeof(head)); } void add(int u,int v,int w){ k[lm].y=v; k[lm].l=w; k[lm].next=head[u]; head[u]=lm++; } int dfs(int x,int p,int l,int be,int ml,int mn ){ if(l-mn>m||ml-l>m){ return p; } if(l>ml)ml=l; if(l<mn)mn=l; p-=be; p+=sp[x].p; int minn=p; for(int i=head[x];~i;i=k[i].next){ int y=k[i].y,pr=k[i].l; if(vis[y])continue ; vis[y]=1; int ans=dfs(y,p,sp[y].l,pr,ml,mn); minn=min(minn,ans); vis[y]=0; } return minn; } int main(){ while(cin>>m>>n){ init(); for(int i=1;i<=n;i++){ scanf("%d%d%d",&sp[i].p,&sp[i].l,&sp[i].n); for(int j=0;j<sp[i].n;j++){ int x,y; scanf("%d%d",&x,&y); add(i,x,sp[i].p-y); } } memset(vis,0,sizeof(vis)); vis[1]=1; cout<<dfs(1,0,sp[1].l,0,sp[1].l,sp[1].l)<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator