-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGarotoIxpertinho.py
34 lines (28 loc) · 1.09 KB
/
GarotoIxpertinho.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import networkx as nx
'''
Autor: Gabriella Mara
Version: 1.0
'''
QCT = input().split()
while not (QCT.count('0') == 3):
Q = int(QCT[0]) #Quantidade de quarteirões/vértices
C = int(QCT[1]) #Quantidade de arestas
T = float(QCT[2]) #Fôlego
g = nx.Graph()
for i in range(0,C):
XYZ = input().split()
X = int(XYZ[0]) #Vértice de origem
Y = int(XYZ[1]) #Vértice de destino
Z = float(XYZ[2]) #Tempo para ir de um ao outro
g.add_nodes_from([X, Y])
g.add_edge(X, Y, time = Z)
minTree = nx.minimum_spanning_tree(g,'time') #Árvore geradora mínima do grafo
timeTotal = 0
nSum = 0
for x, y, time in minTree.edges.data('time'):
if(time > T): #Se o tempo entre os dois vértices for maior que o tempo que ele tem de fôlego
time += 2.0 #Somar os 2 minutos
nSum += 1 #Acrescentar uma pausa
timeTotal += time #Acrescentar, ao tempo total, o tempo de caminhada entre os dois vértices
print("%.2f" %timeTotal, nSum)
QCT = input().split()