Inverse topological sequencing, began to live a not off, and later found that their own methods of recording wages are problematic ..... A blunder.
#include <iostream> #include <queue> #include <vector> #include <cstdio> #define MAXN 10000+100 Using namespace std;vector<vector<int> >mapp;int head[maxn];int money[maxn];int n,m;void topo () {int sum=0, t=0;queue<int>root;for (int i=1;i<=n;i++) {if (!head[i]) Root.push (i);} Salary++;while (Root.size ()) {int X=root.front (); Root.pop (); int temp=money[x];//sum+=salary;t++;for (int i=0;i< Mapp[x].size (); i++) {head[mapp[x][i]]--;if (!head[mapp[x][i]]) Root.push (Mapp[x][i]), money[mapp[x][i]]=temp+1;} if (flag) salary++;} if (t==n) {sum+=n*888;for (int i=1;i<=n;i++) Sum+=money[i];cout<<sum<<endl;} Else cout<< "-1" <<ENDL;} int main () {while (scanf ("%d%d", &n,&m)!=eof) {mapp.resize (n+1); for (int i=0;i<n+1;i++) money[i]=head[i]=0, Mapp[i].clear (); while (m--) {int x,y;cin>>x>>y;mapp[y].push_back (x); head[x]++;} Topo ();} return 0;}
Hdu 2647 Reward