We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Graph Theory
- Jeanie's Route
- Discussions
Jeanie's Route
Jeanie's Route
Sort by
recency
|
28 Discussions
|
Please Login in order to post a comment
A questão apresentada descreve um problema de roteamento em um grafo ponderado, onde Jeanie, uma carteira, precisa entregar cartas em diferentes cidades de Byteland. O objetivo é encontrar a distância mÃnima que Jeanie precisa percorrer para entregar todas as cartas.
POREM SOMENTE COMPILA ERRO :
import math import os import sys import itertools
def min_delivery_distance(n, letters, roads): # Construir o grafo (lista de adjacências) graph = [[] for _ in range(n)] for u, v, w in roads: graph[u - 1].append((v - 1, w)) graph[v - 1].append((u - 1, w))
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')
How could the editorial solve the problem with cities={2, 3} and roads={{1, 2, 1}, {1, 3, 3}, {2, 4, 2}, {3, 4, 4}}? It's a 4-node graph connected in a circle. The editorial would return 20-9=11 instead of the expected result of 4?
Java solution. First, remove outer, non-letter cities (will never be visited). Then, from the (new) outer letter cities, go inward until you reach an intersection city (3 or more edges) and calculate the minimum and maximum subtree value. You can consider a 'minimum' subtree is where you start or end a path at that subtree. A maximum subtree will double value of all "lines" in the subtree. Eventually, you will reach an inner city in which all subtrees are calculated. From there you can calculate an intersection's cities minimum path will add two minimum subtrees with the rest as maximum subtrees. Once you've reached the most inner intersection city, you can calculate it's minimum path and move back outerwards to calcuate the rest of the intersections minimum paths (with optimizations). One of the intersections will have the minimum path, and that's what you will return. Minimum is O(# cities), maximum is O(# cities + # edges).
python3
how can we know which city is must delivered or not ?? The thing we could know is the number of letter.. isn't it??