Cây nhi: lqdoj c++/pas Tùng Dương có một cây (đồ thị vô hướng liên thông và không có chu trình) gồm N đỉnh được đánh số từ 1 đến N. Dương đặt tên cây này là cây Nhi. Mỗi cạnh của cây Nhi đều được tô một màu nào đó trong N−1 màu có sẵn (các màu này được đánh mã từ 1 đến N−1). Cạnh thứ i của cây Nhi nối đỉnh ui với đỉnh vi, đồng thời có độ dài di và được tô màu với mã màu là ci. Dương nhờ bạn lập trình trả lời Q truy vấn, trong đó, truy vấn thứ j cho biết bốn số nguyên xj, yj, uj, vj và yêu cầu bạn cập nhật độ dài của tất cả các cạnh được tô màu với mã màu xj thành yj, sau đó in ra khoảng cách giữa đỉnh uj và đỉnh vj (các thay đổi trên không được áp dụng cho các truy vấn tiếp theo). Bạn hãy ra tay giúp đỡ Dương làm chủ được cây Nhi nhé! Input Dòng đầu chứa hai số nguyên dương N và Q (2≤N≤10^5, 1≤Q≤10^5). Dòng thứ i trong N−1 dòng tiếp theo chứa bốn số nguyên ui, vi, ci và di. Dòng thứ j trong Q dòng tiếp theo chứa bốn số nguyên xj, yj, uj và vj. Ouput In ra Q dòng là câu trả lời cho các truy vấn tương ứng. Ví dụ Sample input 1 5 3 1 2 1 10 1 3 2 20 2 4 4 30 5 2 1 40 1 100 1 4 1 100 1 5 3 1000 3 4 Sample output 1 130 200 60

Các câu hỏi liên quan

VIII- Complete this text by putting in the correct passive forms of the verbs in brackets. Rugby Union Rugby is a team that (1.play) ………………………….in Britain since the middle of the 19 th century. According to legend, it (2.invent) ………………………….at Rugby School in England in 1823 by a boy who (3.call) …………………………. William Webb Ellis. A game of football (4.play) …………………………. at the school when William Webb Ellis suddenly picked up the ball and ran with it. This story might (5.make up)………….. ……………but it (6.tell) ………………….whenever the history of the game (7.explain) ………………………….. Towards the end of the 19 th century, official rules for the game (8.write) ………………………….and it began (9.play) ………………………….in more and more countries, such as France, Australia, New Zealand and South Africa. International matches and tours (10.organize) ………………………….since the beginning of the 20 th century and since 1987 a World Cup tournament (11.hold) ………………………….. At present, more and more countries (12.add) …………………………. to the list of those that take part in the tournament. Television audiences for international matches are high and it is hoped that the game (13.watch) …………………………. by even more people in the future. Until 1995, Rugby Union was an n amateur game but the top players said that they were in favor of (14.pay) …………………………. to play and that the sport should (15.turn into) …………………………. a professional one. despite various problems, this seem (16.do) ………………………….successfully and the sport is growing in popularity, with spectator numbers rising in Britain and elsewhere. In Rugby Union, there are 15 players in each team and different skills (17.require) …………………. in each position. People of all shapes and sizes (18.attract) …………….to the game because some positions (19.suit) ………………………….to very big people while others can (20.fill) …………………………. by smaller people. giúp em với