WA了别看了 我就留个纪念 以后再看
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <climits>
using namespace std;
int n,m,a[100001],d[100001];
bool cc[100001];
vector<int> b[100001];
int solve(int i)
{
if(d[i] != INT_MIN)
return d[i];
d[i] = a[i];
for(int j=0;j<b[i].size();++j)
d[i] = max(d[i],a[i]+solve(b[i][j]));
return d[i];
}
int main()
{
while(scanf("%d %d",&n,&m) != EOF)
{
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
a[0] = 0;
//初始化
int x,y;
for(int i=0;i<=n;++i)
{
b[i].clear();
d[i] = INT_MIN;
cc[i] = false;
}
//初始化
for(int i=1;i<=m;++i)
{
scanf("%d %d",&x,&y);
b[x].push_back(y);//x可以到y
cc[y] = true;//y入度不为0
}
for(int i=1;i<=n;++i)
if(b[i].size()!=0&&!cc[i])
b[0].push_back(i);
//0 指向 入度不为零的点
printf("%d\n",solve(0));
}
return 0;
}