Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA到吐,这种题做的不多,但实在想不出来我的方法有什么错误

Posted by smallbox at 2008-11-16 16:25:03 on Problem 3249
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator