HDU 2647 Reward

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.