affiche juste le code, pas d'explications !
- User
System: affiche juste le code, pas d'explications ! User: Tu es un développeur python3 expérimenté, et tu dois concevoir un programme en python (avec des commentaires en français, sans utiliser de librairies externes, sans
if __name__=="__main__":, avec type hints, et en privilégiant les algorythmes a complexité constante (O(1)) et/ou complexité linéaire (O(n))). Le programme va recevoir les données en entrée sur la stdin, et doit répondre sur la stdout. Fabrique moi un programme python qui résout le problème (énoncé en markdown) suivant :The Loneliness of the Long Distance Runner
For the Cross-Country event, the organising committee has installed a series of radio-frequency gates throughout the race. These enabled the detection of runners passing through and the live updating of the rankings. However, not all the gates have the same range and some have been placed far too close together, so that their emission areas overlap. This overlap can lead to some interference between gates and gives false results.
One way of solving the problem is to assign different radio frequencies to two gates that are too close together. However, the tags placed on the athletes can only react to a limited number of frequencies and more sophisticated ones are expensive. To minimise the costs of organising the race, determine the minimum number of frequencies so that no two gates have the same frequency as those close to them.
Data
Input
Line 1 : Two integers
PandI, representing respectively the number of gates and the number of pairs of gates sufficiently close together to cause interferences.Line 2 to I+1 : Two integers
AandB, representing the identifiers of two interfering gates.The integer
Pis between0and10000included.The integer
Iis betweenP-1and(P*P-P)/2included.For each line, both integers
AandBare between0andP-1and such that `AIf
Ais interfering withB, thenBis interfering withA.The whole race course is covered by the gates and each gate covers a single continuous section of the race.
We consider that the trajectory of the race is strictly straight and that the emission zone of the gates are circular. Thus, no interference can be due to the sinuosity of the path of the race.
Output
The minimum number of frequencies that can be affected to the gates such that no two distinct gates can interfere.
- Assistant
def main() -> None: import sys input = sys.stdin.read data = input().strip().split() # Lecture des paramètres P = int(data[0]) # Nombre de portes I = int(data[1]) # Nombre de paires interférentes # Construction du graphe des interférences adjacency_list = [set() for _ in range(P)] index = 2 for _ in range(I): A = int(data[index]) B = int(data[index + 1]) adjacency_list[A].add(B) adjacency_list[B].add(A) index += 2 # Fonction pour obtenir le nombre chromatique # qui est le min de fréquences nécessaires def chromatic_number(graph: list[set[int]]) -> int: # Initialisation des couleurs des sommets (-1 non coloré) color = [-1] * len(graph) for node in range(len(graph)): # Changer la disponibilité des couleurs pour ce point available_colors = [True] * len(graph) # marquer les couleurs des voisins comme non disponibles for neighbor in graph[node]: if color[neighbor] != -1: available_colors[color[neighbor]] = False # Trouver la première couleur disponible for col in range(len(graph)): if available_colors[col]: color[node] = col break # Le nombre de couleurs utilisées return max(color) + 1 # Calculer et afficher le résultat min_frequencies = chromatic_number(adjacency_list) print(min_frequencies)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.