GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday, 4 September 2022

[Solution] Journey Codeforces Solution | Solution Codeforces


J. Journey
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day, Pak Chanek who is already bored of being alone at home decided to go traveling. While looking for an appropriate place, he found that Londonesia has an interesting structure.

According to the information gathered by Pak Chanek, there are N cities numbered from 1 to N. The cities are connected to each other with N1 two-directional roads, with the i-th road connecting cities Ui and Vi, and taking a time of Wi hours to be traversed. In other words, Londonesia's structure forms a tree.

Pak Chanek wants to go on a journey in Londonesia starting and ending in any city (not necessarily the same city) such that each city is visited at least once with the least time possible. In order for the journey to end quicker, Pak Chanek also carries an instant teleportation device for moving from one city to any city that can only be used at most once. Help Pak Chanek for finding the minimum time needed.

Notes:

  • Pak Chanek only needs to visit each city at least once. Pak Chanek does not have to traverse each road.


Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇


  • In the journey, a city or a road can be visited more than once.
Input

The first line contains a single integer N (1N105) — the number of cities in Londonesia.

The i-th of the next N1 lines contains three integers UiVi, and Wi (1Ui,ViN1Wi109) — a two-directional road that connects cities Ui and Vi that takes Wi hours to be traversed. The roads in Londonesia form a tree.

Output

Output one integer, which represents the minimum time in hours that is needed to visit each city at least once.

No comments:

Post a Comment