hust 1608--Dating With Girls

Description

If you have a date with a pretty girl in a hurry, you can ignore what I will say next.
 
Hellis is a little bad guy in Rural Small Technical College. And the most important fact is that he is especially fond of glaring at pretty girls! And as we all know, there are some girls he favors in the same school. So there comes the trouble. On one terrible day, it should rains. The girls all are being different places. They all phone him and ask the boy to deliver them umbrellas at the same time. However, the cute boy faces the embarrassing condition. You can have a simple Understanding that each girl has a special relationship with our sunny boy. If they know the boy sends the umbrella to anyone of them, the others may go mad and that is not the boy expects. If that happens, Of course you will never see that he is completing again. But the fact is some girls are so beautiful and he would like to give them help. The trouble is this guy wants to meet more beautiful girls before he arrives at anyone who phones him for help. It is just a disaster, he thinks. Eventually, he makes the choice. He will just send an umbrella to only one girl who is most important to him, and he can not be seen by other girls who phones him for help. If that happens, I can only say hehe. He must pass these girls. In the process, he can send beautiful girls their umbrellas! In that case, he can create a chance to communicate with them and just win their favorable impression. It is such a good idea!
 
There are n different places in our problem. There are m different undirectional edges. And there is no loop. The bad guy starts at 1 node, and other 2 to n node stand different girls. Each girl is standing at different nodes, too. The i-th girl has wi. When Hellis meets a girl, he can get |wi| point, and he wants to get max sum of point he gets.(wi<0 mean the i-th girl has phoned him for help

Input

First line, two integers, n ,m (1<n<100, 1<m<5000)
2th to (m+1)th per line ,ai, bi (0<ai<=n, 0<bi<=n) means one road from ai to bi.
(m+2)th to (n+m)th per line, wi (0<|wi|<=100, 2<=i<=n) 

Output

If the guy can meet the girl they chose, output line print a single integer ans — the max sum of point he gets.
Else print “What is a fucking day!” 

Sample Input

3 3
1 2
1 3
2 3
-30
10

Sample Output

30

题意一个人从点1出发,给出后面每个点的权值,以及连通情况,问到达所有点中权值最小的点的过程中不能经过其它负权值点所获得的最大权值
= =解释的好绕口。。。
一开始用的dfs没有能够实现,看别人写的后,改用bfs,才弱弱的过了。。唉
View Code
 1 #include <cstdio>
 2 #include <cstring>
 3 using namespace std;
 4 const int N=105;
 5 const int INF=1<<29;
 6 int dis[N],vis[N],ans[N],head[N],q[5000];
 7 int cnt,n,maxx;
 8 struct eg
 9 {
10     int to;
11     int next;
12 }p[5000];
13 void addedge(int u,int v)
14 {
15     p[cnt].to=v;
16     p[cnt].next=head[u];
17     head[u]=cnt++;
18 }
19 void bfs()
20 {
21     int i,v,l,r=0;
22     memset(vis,0,sizeof(vis));
23     memset(ans,-1,sizeof(ans));
24     q[r++]=1;
25     ans[1]=0;vis[1]=1;
26     for(l=0;l<r;l++)
27     {
28         int t=q[l];
29         for(i=head[t];i!=-1;i=p[i].next)
30         {
31             if(dis[v=p[i].to]>0)
32                 if(ans[v]<ans[t]+dis[v])
33                     ans[v]=ans[t]+dis[v];
34             if(dis[v]==-maxx)
35                     if(ans[v]<ans[t]-dis[v])
36                         ans[v]=ans[t]-dis[v];
37             if(!vis[v]&&dis[v]>0)
38             {
39                 q[r++]=v;
40                 vis[v]=1;
41             }
42         }
43         vis[t]=0;
44     }
45 }        
46 int main()
47 {
48     int m,i,k,u,v;
49     while(scanf("%d%d",&n,&m)!=EOF)
50     {
51         k=-1,cnt=0;
52         memset(head,-1,sizeof(head));
53         for(i=0;i<m;i++)
54         {
55             scanf("%d%d",&u,&v);
56             addedge(u,v);
57         }
58         maxx=dis[1]=0;
59         for(i=2;i<=n;i++)
60         {
61             scanf("%d",&dis[i]);
62             if(dis[i]<0)
63                 if(-dis[i]>maxx)
64                 {
65                     maxx=-dis[i];
66                     k=i;
67                 }
68         }
69         bfs();
70         if(k==-1||ans[k]<0)
71             printf("What is a fucking day!\n");
72         else
73             printf("%d\n",ans[k]);    
74     }
75     return 0;
76 }

 

posted @ 2013-03-16 21:13  Tamara.c  阅读(240)  评论(0编辑  收藏  举报