Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- int n, m;
- cin>>n>>m;
- vector<vector<array<ll int, 3>>> va(n);
- for(int i=0; i<m; i++)
- {
- int a, b, x, y;
- cin>>a>>b>>x>>y;
- a--, b--;
- va[a].pb({b, x, y});
- va[b].pb({a, -x, -y});
- }
- vector<pair<ll int, ll int>> ans(n, {-1e18, -1e18});
- ans[0] = {0, 0};
- vector<int> vis(n);
- function<void(int)> DFS = [&](int u)
- {
- vis[u] = 1;
- for(auto [v, a, b]: va[u])
- {
- if(vis[v]) continue;
- ans[v] = {a+ans[u].ff, b+ans[u].ss};
- DFS(v);
- }
- };
- DFS(0);
- for(auto [x, y]: ans)
- {
- if(x == -1e18)
- cout<<"undecidable\n";
- else
- cout<<x<<" "<<y<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment