Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views2 pages

Homework Lecture 11 Shortest Path: Tips: - Finding The Minimal Dirty Level (Called X)

The document outlines a homework assignment focused on finding the shortest path between cities based on a 'dirty level' metric. It specifies two tasks: writing a program to determine the path with the smallest total dirty level from a starting city to an endpoint, and calculating the shortest paths for all pairs of cities. Input is taken from a file named 'dirty.txt' and results are outputted to 'dirty.out' with specific formatting requirements.

Uploaded by

Dức Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

Homework Lecture 11 Shortest Path: Tips: - Finding The Minimal Dirty Level (Called X)

The document outlines a homework assignment focused on finding the shortest path between cities based on a 'dirty level' metric. It specifies two tasks: writing a program to determine the path with the smallest total dirty level from a starting city to an endpoint, and calculating the shortest paths for all pairs of cities. Input is taken from a file named 'dirty.txt' and results are outputted to 'dirty.out' with specific formatting requirements.

Uploaded by

Dức Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Homework lecture 11

Shortest Path
Given n cities (numbered from 1 to n) and m roads connecting cities. The dirty level
between two cities u, v is D[u,v] (D[u,v] might be negative). You have two tasks:

a. Write a program to find a path from a starting point s to the end point e
such that the total dirty level on the path is the smallest.
b. Write a program to find the shortest paths for all pairs of vertices

Input: Data come from file dirty.txt in the following format:

- The first line contains four integer numbers n, m, s, e


- m following lines each contains 3 integer numbers u, v, d indicating that the
dirty level of road from u to v is d.

Output: Results are written to file “dirty.out” in the following format:

- The first line contains the total dirty level of the path from s to e.
- The second line contains cities on the path from s to e.
- The next n lines each contains n integer numbers are the shortest distance
matrix for all pairs of vertices. (output INF if there is no path between two
cities).

Example:

dirty.txt dirty.out

5932 8

125 312

232 05623

434 50278

451 38056

511 24401

523 13530

357

142

313

Tips:

- Finding the minimal dirty level (called X).


- Each dirty level D[u,v]: D[u,v]=D[u,v]+ |X|. So that every dirty level is not negative.

- Apply Dijkstra algorithm to find the shortest path from s to e.

- Apply FLOYD Algorithm to find the shortest paths for every vertex pairs (u,v).

You might also like