Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: mickyta1
- TASK: concom
- LANG: C++
- */
- #include <bits/stdc++.h>
- using namespace std;
- typedef pair<int, int> pii;
- const int N = 100 + 5;
- vector<pii> adj[N];
- int con[N];
- void BFS(int st){
- for(int u = 0; u <= 100; ++u){
- con[u] = 0;
- }
- con[st] = 100;
- vector<int> ans;
- queue<int> que;
- que.push(st);
- while(!que.empty()){
- int u = que.front();
- que.pop();
- if(u != st){
- ans.push_back(u);
- }
- for(pii nxt : adj[u]){
- int v = nxt.first;
- int w = nxt.second;
- if(con[v] <= 50){
- con[v] += w;
- if(con[v] > 50){
- que.push(v);
- }
- }
- }
- }
- sort(ans.begin(), ans.end());
- for(int x : ans){
- cout << st << ' ' << x << '\n';
- }
- }
- int main(){
- freopen("concom.in", "r", stdin);
- freopen("concom.out", "w", stdout);
- int Q;
- scanf("%d", &Q);
- while(Q--){
- int u, v, w;
- scanf("%d%d%d", &u, &v, &w);
- adj[u].emplace_back(v, w);
- }
- for(int u = 1; u <= 100; ++u){
- BFS(u);
- }
- fclose(stdin);
- fclose(stdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement