7_9_2013 B: Dating With Girls

Problem B: Dating With Girls

Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 27   Solved: 22
[ Submit][ Status][ Web Board]

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 different places in our problem. There are different undirectional edges. And there is no loop. The bad guy starts at 1 node, and other 2 to 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 |wipoint, and he wants to get max sum of point he gets.(w0 means the i-th girl has phoned him for help). 

Input

Multiple test cases. For each test case:
First line, two integers, 
,(1 < n < 100, 1 < m < 5000)

2th to (m+1)th per line,ai,b(0<an,0<bn)means one road from ato bi.

(m+2)th to(n+m)th per line,w(0<|wi|≤100,2in

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!0(without the quotes). 

Sample Input

3 3 1 2 1 3 2 3 -30 10

Sample Output

30
Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 27   Solved: 22
[ Submit][ Status][ Web Board]

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 different places in our problem. There are different undirectional edges. And there is no loop. The bad guy starts at 1 node, and other 2 to 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 |wipoint, and he wants to get max sum of point he gets.(w0 means the i-th girl has phoned him for help). 

Input

Multiple test cases. For each test case:
First line, two integers, 
,(1 < n < 100, 1 < m < 5000)

2th to (m+1)th per line,ai,b(0<an,0<bn)means one road from ato bi.

(m+2)th to(n+m)th per line,w(0<|wi|≤100,2in

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!0(without the quotes). 

Sample Input

3 3 1 2 1 3 2 3 -30 10

Sample Output

30
Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 27   Solved: 22
[ Submit][ Status][ Web Board]

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 different places in our problem. There are different undirectional edges. And there is no loop. The bad guy starts at 1 node, and other 2 to 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 |wipoint, and he wants to get max sum of point he gets.(w0 means the i-th girl has phoned him for help). 

Input

Multiple test cases. For each test case:
First line, two integers, 
,(1 < n < 100, 1 < m < 5000)

2th to (m+1)th per line,ai,b(0<an,0<bn)means one road from ato bi.

(m+2)th to(n+m)th per line,w(0<|wi|≤100,2in

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!0(without the quotes). 

Sample Input

3 3 1 2 1 3 2 3 -30 10

Sample Output

30


#include <iostream>
#include <stdio.h>
#include <queue>
#include <math.h>
#include <string.h>
using namespace std;
int map[110][110],val[110], vis[110],mmax[105];
int n,m;
int x, y, flag, mins;

void bfs()
{
    memset(vis, 0,sizeof(vis));
    for(int i=1; i<=n; i++){
        mmax[i]=-1000;
    }
    queue<int>my;
    mmax[1]=0;
    my.push(1);
    vis[1]=1;
    while(!my.empty()){
        int temp=my.front();
        my.pop();
        for(int i=1; i<=n; i++){
            if(map[temp][i]){
                if(val[i]>0){
                    if(mmax[i]<mmax[temp]+val[i])
                    mmax[i]=mmax[temp]+val[i];
                }

                else{
                    if(mmax[i]<mmax[temp]-val[i])
                        mmax[i]=mmax[temp]-val[i];
                }
                if(!vis[i]&&val[i]>0){
                my.push(i);
                vis[i]=1;
                }
            }
        }
        vis[temp]=0;
    }
}
int
main()
{
    while(cin>>n>>m){
        memset(map, 0, sizeof(map));
        for(int i=0; i<m; i++){
            cin>>x>>y;
            map[x][y]=1;
        }
        mins=10000;
        for(int i=2; i<=n; i++){
            cin>>val[i];
            if(mins>val[i]){
                mins=val[i];
                flag=i;
            }
        }
        bfs();
        if(mmax[flag]>=0){
            cout<<mmax[flag]<<endl;
        }
        else{
            cout<<"What is a fucking day!\n";
        }
    }
    return 0;
}

你可能感兴趣的:(7_9_2013 B: Dating With Girls)