Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<queue>
- #include<algorithm>
- using namespace std;
- int who_zero[101];
- int ans[101];
- int power[101][101];
- int n,m;
- vector<int> vec[101];
- vector<int> f_part;
- queue<int> q;
- void limit(int weight,int y,int x);
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- cin>>n>>m;
- for(int i=1;i<=m;i++)
- {
- int x,y,k;
- cin>>x>>y>>k;
- vec[x].push_back(y);
- who_zero[x]++;
- power[x][y]=k;
- }
- for(int i=1;i<=n;i++)
- if(who_zero[i]==0) f_part.push_back(i);
- //
- q.push(n);
- while(!q.empty())
- {
- int qs;
- qs=q.size();
- while(qs--)
- {
- int order=q.front();
- q.pop();
- for(int i=0;i<vec[order].size();i++)
- {
- limit(power[order][vec[order][i]],vec[order][i],order);
- }
- }
- }
- //
- sort(f_part.begin(),f_part.end());
- for(int i=0;i<f_part.size();i++)
- {
- cout<<f_part[i]<<" "<<ans[f_part[i]]<<"\n";
- }
- return 0;
- }
- void limit(int weight,int y,int x)
- {
- if(vec[y].size()==0)
- ans[y]+=weight;
- else {
- for (int i = 0; i < vec[y].size(); i++) {
- int t = vec[y][i];
- limit(power[y][t] * weight, t,y);
- }
- }
- }
Add Comment
Please, Sign In to add comment