1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 const int N=205; 5 int a[N][N],c[N],f[N]; 6 int main(){ 7 int n,x,y,t,r,maxx=0; 8 cin>>n; 9 for(int i=1;i<=n;i++)cin>>a[i][i]; 10 while(cin>>x>>y){ 11 if(!x&&!y)break; 12 a[x][y]=1; 13 } 14 for(int i=1;i<=n;i++){ 15 f[i]=a[i][i]; 16 for(int j=1;j<i;j++){ 17 if(a[j][i]&&f[j]+a[i][i]>f[i]){ 18 f[i]=f[j]+a[i][i]; 19 c[i]=j;//表示最好从j处挖到i处 20 } 21 } 22 if(f[i]>maxx){ 23 maxx=f[i]; 24 t=i; 25 } 26 } 27 while(c[t]){ 28 r=c[t]; 29 c[t]=-1; 30 t=r; 31 } 32 cout<<t; 33 while(++t<=n){ 34 if(c[t]<0)printf("-%d",t); 35 } 36 printf("\n%d",maxx); 37 return 0; 38 }