Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream in("modernizare.in");
  6. ofstream out("modernizare.out");
  7.  
  8. int n,m,f,v[1001][1001],v2[100001],s[100001],p;
  9. deque < int > c;
  10.  
  11. int main()
  12. {
  13. in>>n>>m>>f;
  14.  
  15. for(int i=1;i<=m;i++)
  16. { int a,b,x;
  17. in>>a>>b>>x;
  18. v[a][b]=x;
  19. v[b][a]=x;
  20. }
  21.  
  22. v2[1]=1;
  23. c.push_back(1);
  24.  
  25. while( !c.empty() )
  26. {int k=1;
  27. for(int i=1;i<=n;i++)
  28. if(v[c.front()][i]!=0)
  29. if(v2[i]==0)
  30. {
  31. c.push_back(i);
  32. v2[i]=1;
  33. }
  34.  
  35. for(int i=1;i<c.size();i++)
  36. s[i]=v[i][c.front()];
  37.  
  38. sort(s+1,s+c.size());
  39.  
  40. for(int i=0;i<c.size();i++)
  41. if(c[i]!=c.front()) if(v[c[i]][c.front()]!=0) if(v[c[i]][c.front()]<=f) {f=f-v[c[i]][c.front()]; p++; }
  42. else {k=0; break;}
  43.  
  44. if(k==0) break;
  45. if(f==0) break;
  46.  
  47. c.pop_front();
  48. }
  49.  
  50. out<<p;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement