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 best protection
You are quickly making your mark in the Brigade. Since your exploits in the previous challenge, you have been one of the most promising members of the Order. But during your missions, you have noticed that a very powerful meta-human is moving faster than you, and anticipates certain disasters even better than the Brigade...
You don't tell your management yet, but you start your research on this mysterious and unknown benefactor of the Brigade. In your search, you notice a strange pattern: it seems that he is moving around helping those who need it most.
To begin your search, you decide to focus solely on the project to protect the space cities. These cities are composed of 2 types of modules: the housing modules and the control modules, and each module can protect one or several others. There are never cycles in the protection relationship (for example, if A protects B and B protects C, then C does not protect A).
Modules that protect at least one other module are control modules, and those that do not protect any other module are home modules. Find the controller in the city that controls the most housing modules to see which neighborhood can protect the most residents at once.
Data
Input
Line 1: Two integers
NandVindicating how many protection relationships there are and how many modules (numbered from 0 toV-1)N following lines : Two integers
aandbindicating that moduleaprotects moduleb.1 ≤ N < V ≤ 11 000Output
Line 1 An integer indicating the controller managing the most housing modules.
Example
For input:
plaintext8 10 8 4 7 2 6 8 6 1 7 9 6 7 2 0 5 3The solution is :
plaintext6The first line shows 8 relationships and 10 modules numbered 0 to 9. Here module 6 controls 4 house modules (0, 1, 4, 9), while controller 5 controls only one (3). So 6 is the answer.
- Assistantpython