Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1651 - Graf
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Exemplul 1: = Intrare 5 6 1 2 10 2 3 2 2 5 2 3 5 12 3 4 1 4 5 5 Ieșire 4 === Explicație === Mediile ponderilor muchiilor incidente cu vârfurile grafului sunt: * pentru vârful <code>1</code> media este <code>10</code> * pentru vârful <code>2</code> media este <code>4.66667</code> * pentru vârful <code>3</code> media este <code>5</code> * pentru vârful <code>4</code> media este <code>3</code> * pentru vârful <code>5</code> media este <code>6.33333</code> Astfel media minimă este <code>3</code>, pentru vârful <code>4</code> == Exemplul 2: == <code>Intrare</code> <code>101</code> <code>consola</code> Datele nu corespund restrictiilor impuse == Rezolvare == <syntaxhighlight lang="python3" line="1"> from typing import List, Tuple def check_constraints(n, m, edges): if not (1 <= n <= 100): return False for edge in edges: i, j, p = edge if not (1 <= i <= n) or not (1 <= j <= n) or not (1 <= p < 1000): return False return True def main(): nMAX = 100 mat = [[] for _ in range(nMAX + 1)] # mat[i][0] = (j, p) (edge between i and j with weight p) n, m = map(int, input().split()) if not (1 <= n <= 100): print("Detele nu respecta restrictiile impuse") return edges = [tuple(map(int, input().split())) for _ in range(m)] if not check_constraints(n, m, edges): print("Detele nu respecta restrictiile impuse") return for i, j, p in edges: mat[i].append((j, p)) mat[j].append((i, p)) vfmin = 0 medmin = float('inf') for i in range(1, n + 1): _sum = sum(weight for _, weight in mat[i]) if _sum / len(mat[i]) < medmin: medmin = _sum / len(mat[i]) vfmin = i print(vfmin) if __name__ == "__main__": main() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width