标签:ons inf set job 大于 ios mem run point
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5804 Accepted Submission(s):
1681
#include<iostream> #include<cstdio> #include<vector> #include<set> #include<map> #include<string.h> #include<algorithm> #include<queue> #define inf 0x3f3f3f3f using namespace std; int ma[105][105]; int reach[105][105]; int power[105]; int flod(int n) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) if(reach[i][j]||(reach[i][k]&&reach[k][j])) reach[i][j]=1; if(reach[1][n]) return 1; return 0; } int spfa(int n) { queue<int> run; // int vis[105]={0}; int cnt[105]={0}; int quan[105]; memset(quan,0,sizeof(quan)); run.push(1); //vis[1]=1; cnt[1]++; quan[1]=100; while(!run.empty()) { int cur=run.front(); run.pop(); if(++cnt[cur]>=n) { if(reach[cur][n]) return 1; else break; } for(int i=1;i<=n;i++) if(ma[cur][i]&&quan[i]<quan[cur]+power[i]&&quan[cur]+power[i]>0) { quan[i]=quan[cur]+power[i]; run.push(i); } } if(quan[n]>0) return 1; return 0; } int main() { int n; while(~scanf("%d",&n)) { if(n==-1) break; memset(ma,0,sizeof(ma)); memset(reach,0,sizeof(reach)); memset(power,0,sizeof(power)); for(int i=1;i<=n;i++) { int k; scanf("%d%d",&power[i],&k); for(int j=1;j<=k;j++) { int tem; scanf("%d",&tem); ma[i][tem]=1; reach[i][tem]=1; } } if(!flod(n)) { printf("hopeless\n"); continue; } if(!spfa(n)) printf("hopeless\n"); else printf("winnable\n"); } return 0; }
标签:ons inf set job 大于 ios mem run point
原文地址:http://www.cnblogs.com/brotherHaiNo1/p/7267658.html