| ||||||||||
| 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 | |||||||||
WA到吐,这种题做的不多,但实在想不出来我的方法有什么错误#include "iostream"
#include "vector"
using namespace std;
const int INFI=1<<30;
int N,M;
int P[100000];
int dp[100000];
int In[100000];
vector<int> List[100000];
int ans;
void Pop(int v)
{
int size=List[v].size();
if(size==0)ans>?=dp[v];
for(int i=0;i<size;i++)
{
int to=List[v][i];
dp[to]>?=dp[v]+P[to];
In[to]--;
if(In[to]==0)
Pop(to);
}
}
void TopSort()
{
for(int i=0;i<N;i++)
{
if(In[i]==0)dp[i]=P[i];
else dp[i]=-INFI;
}
for(int i=0;i<N;i++)
if(In[i]==0)Pop(i);
}
main()
{
while(scanf("%d %d",&N,&M)!=EOF)
{
for(int i=0;i<N;i++)
List[i].clear();
for(int i=0;i<N;i++)
scanf("%d",&P[i]);
memset(In,0,sizeof(In));
for(int i=0;i<M;i++)
{
int a,b;
scanf("%d %d",&a,&b);
List[a-1].push_back(b-1);
In[b-1]++;
}
ans=-INFI;
TopSort();
printf("%d\n",ans);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator