hdu 1317 坑爹的数据!!hdu。。。你赢了。。。

/*****************************************************************************
                    盗版sphinx的开头 ~!
*****************************************************************************/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<utility>
#include<complex>
#include<cstdlib>
#include<cassert>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cctype>
#include<limits>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<cmath>
#include<ctime>
#include<list>
#include<map>
#include<set>
using namespace std;
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")
#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define SC(t, s) static_cast<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )
typedef double LF;
//typedef long long LL;     //GNU C++
//typedef unsigned long long ULL;
typedef __int64 LL;     //Visual C++ 2010
typedef unsigned __int64 ULL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;

typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<int>::iterator LI;
typedef set<int>::iterator SI;

const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL;     //15f
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
const int inf=0x7fffffff;

const int maxn=111;
const int maxin=222;     //从22改成222
// f**k!!本来我以为22已经足够大了!因为spfa每个点都是平均进出两次的,尼玛hdu的测试数据能让它进出几百次啊!!有木有....
vector<int>g[maxn];
queue<int>Q;
bool vis[maxn];
bool see[maxn];
bool did[maxn];
int num[maxn];
int power[maxn];
int e[maxn];
int n,m,tv,now,tp,start,end;

inline void init()
{
    memset(num,0,sizeof(num));
    memset(vis,false,sizeof(vis));
    memset(see,false,sizeof(see));
    memset(power,-1,sizeof(power));
    memset(did,false,sizeof(did));
    for(int i=1;i<=n;i++)
    {
        g[i].clear();
    }
    return ;
}

bool spfa()
{
    while(!Q.empty())
    {
        Q.pop();
    }
    Q.push(1);
    power[1]= 100 + e[1];
    num[1]++;
    vis[1]= true;
    while (!Q.empty())
    {
        now = Q.front();
        Q.pop();
        for (int i=0; i < g[now].size(); i++)
        {
            tv = g[now][i];
            tp = power[now] + e[tv];
            if ( tv == n )
            {
                return true;
            }
            if ( tp <= 0 )
            {
                continue;
            }
            if ( tp > power[tv] )
            {
                power[tv] = tp;
                if ( !vis[tv] && !did[tv])
                {
                    if ( num[tv] <= maxin )
                    {
                        Q.push(tv);
                        num[tv]++;
                        vis[tv]=true;
                    }
                    else
                    {
                        if(!did[tv])
                        {
                            power[tv]=inf;
                            Q.push(tv);
                            memset(num,0,sizeof(num));
                            num[tv]=inf;
                            vis[tv]=true;
                            did[tv]=true;
                        }
                    }
                }
            }
        }
        vis[now]=false;
    }
    return false;
}

int main()
{
    while(cin>>n)
    {
        init();
        if(n==-1) break;
        for(int i=1;i<=n;i++)
        {
            cin>>e[i]>>m;
            for(int j=1;j<=m;j++)
            {
                cin>>tv;
                g[i].push_back(tv);
            }
        }
        if( spfa() )
        {
            cout<<"winnable"<<endl;
        }
        else
        {
            cout<<"hopeless"<<endl;
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值