Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #define Nmax 101
- using namespace std;
- ifstream f("festivaluri.in");
- ofstream g("festivaluri.out");
- int n,m,p,z,nr,ec,r,vf[Nmax],a[Nmax][Nmax],costf[Nmax]; /// vf-varfurile cu costfival; ec-energia consumata
- void citire()
- {
- int x,y,co;
- f>>n>>m>>p>>z>>r;
- for(int i=1;i<=m;++i)
- f>>x>>y>>co,a[x][y]=co;
- for(int i=1;i<=r;++i)
- f>>vf[i];
- }
- void roy_floyd() /// Determin drumurile minime
- {
- for(int k=1;k<=n;++k)
- for(int i=1;i<=n;++i)
- for(int j=1;j<=n;++j)
- if(a[i][k]&&a[k][j]&&(a[i][k]+a[k][j]<a[i][j]||!a[i][j])&&i!=j)
- a[i][j]=a[i][k]+a[k][j];
- }
- void sortare()
- {
- for(int i=1;i<=r;++i)
- costf[i]=a[z][vf[i]];
- sort(costf+1,costf+r+1);
- }
- void det_nr_fest() /// Determin nr de fivaluri la care are acces
- {
- ec=0;
- for(int i=1;i<=r;++i)
- if(ec+costf[i]<=p&&costf[i])
- ++nr,ec+=costf[i];
- g<<nr;
- }
- int main()
- {
- citire();
- roy_floyd();
- sortare();
- det_nr_fest();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement