-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
59 lines (53 loc) · 1.03 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//Seen editorial
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
struct Node{
long long to;
long long x;
long long y;
};
long long vis[200005];
vector<Node> adj[200005];
vector<pair<long long,long long> > pos(200005);
void DFS(long long v,long long x,long long y)
{
vis[v]=1;
pos[v]={x,y};
for(long long i=0;i<adj[v].size();i++)
{
if(!vis[adj[v][i].to])
{
DFS(adj[v][i].to,x+adj[v][i].x,y+adj[v][i].y);
}
}
}
int main()
{
fastio;
long long n,m,i,j,u,v,x,y;
cin>>n>>m;
for(i=0;i<m;i++)
{
cin>>u>>v>>x>>y;
u--;
v--;
Node nd;
nd.to=v;
nd.x=x;
nd.y=y;
adj[u].push_back(nd);
nd.to=u;
nd.x=(-1)*x;
nd.y=(-1)*y;
adj[v].push_back(nd);
}
DFS(0,0,0);
for(long long i=0;i<n;i++)
{
if(vis[i])
cout<<pos[i].first<<" "<<pos[i].second<<"\n";
else
cout<<"undecidable\n";
}
}