Giter Site home page Giter Site logo

cgreenp / nptel-programming-assignment-padayatra Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18 KB

NPTEL Programming Assignment: Padayatra

License: GNU General Public License v3.0

C++ 100.00%
cpp design-and-analysis-of-algorithms graphs graphs-algorithms nptel nptel-assignments nptel-solutions weighted-graphs

nptel-programming-assignment-padayatra's Introduction

NPTEL-Programming-Assignment-Padayatra

NPTEL Programming Assignment: Padayatra

Padayatra

The exit polls indicate that the sitting MLA is likely to lose the upcoming election. The party high command instructs him to undertake a padayatra through his constituency to boost his popularity. To maximize coverage of the constituency, the party decides that he should choose a circular route that returns to the starting point without using any road twice. The route need not visit all the towns and villages in the constituency.

Being averse to physical exercise, the MLA would like to minimize the distance that he has to walk. He has a helicopter at his disposal, so he can begin the padayatra at any town or village.

The task is to help him find the shortest circular route. You are guaranteed that there is always at least one circular route.

Solution Hint

Given an edge (i,j) with weight W(i,j), the shortest cycle from i to i via j can be found by temporarily deleting the edge (i,j), finding the shortest path from j to i, and then adding W(i,j) to the length of this path. Do this systematically to find the shortest cycle in the graph.

Input format

The first line of input is an integer N, 1 ≤ N ≤ 1000, the number of roads in the constituency. The constituency has no more than 300 towns and villages connected by roads.

The next N lines specify the roads. Each line consists of three space separated integers S, T and D where S is the starting point of the road, T is the ending point and D is the length of the road. Each road is a two-way road and is listed exactly once, in one of the two directions

Output format

A single line with the integer distance around the shortest possible circular route.

Test data

There are at most 300 towns and villages and at most 1000 roads.

Example

Sample Input

4
3 1 5
1 2 4
3 2 3
1 5 44

Sample output 1

12

nptel-programming-assignment-padayatra's People

Contributors

cgreenp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.