Guest User

Untitled

a guest
Jul 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<queue>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. int who_zero[101];
  8. int ans[101];
  9. int power[101][101];
  10. int n,m;
  11. vector<int> vec[101];
  12. vector<int> f_part;
  13.  
  14. queue<int> q;
  15.  
  16.  
  17. void limit(int weight,int y,int x);
  18.  
  19. int main()
  20. {
  21. ios::sync_with_stdio(false);
  22. cin.tie(NULL);
  23. cin>>n>>m;
  24. for(int i=1;i<=m;i++)
  25. {
  26. int x,y,k;
  27. cin>>x>>y>>k;
  28. vec[x].push_back(y);
  29. who_zero[x]++;
  30. power[x][y]=k;
  31. }
  32. for(int i=1;i<=n;i++)
  33. if(who_zero[i]==0) f_part.push_back(i);
  34. //
  35. q.push(n);
  36. while(!q.empty())
  37. {
  38. int qs;
  39. qs=q.size();
  40. while(qs--)
  41. {
  42. int order=q.front();
  43. q.pop();
  44.  
  45. for(int i=0;i<vec[order].size();i++)
  46. {
  47. limit(power[order][vec[order][i]],vec[order][i],order);
  48.  
  49. }
  50.  
  51. }
  52. }
  53. //
  54.  
  55. sort(f_part.begin(),f_part.end());
  56. for(int i=0;i<f_part.size();i++)
  57. {
  58. cout<<f_part[i]<<" "<<ans[f_part[i]]<<"\n";
  59. }
  60. return 0;
  61. }
  62.  
  63. void limit(int weight,int y,int x)
  64. {
  65.  
  66. if(vec[y].size()==0)
  67. ans[y]+=weight;
  68. else {
  69. for (int i = 0; i < vec[y].size(); i++) {
  70. int t = vec[y][i];
  71. limit(power[y][t] * weight, t,y);
  72. }
  73. }
  74. }
Add Comment
Please, Sign In to add comment