PROGRAMMING:Dictionary representation of Graphs
![ Capture. JPG] (~ / 87229a21-351c-4d82-9dba-6f35d8287f78. JPG)
Dictionary representation of graphs. Input multiple lines of string, each line represents a vertex and its connected edge and length, output vertex number, edge number, total length of edge. For example, point 0 in the figure above shows:
{'O':{'A':2,'B':5,'C':4}}。 Use the eval function to process the input. For the specific usage of the eval function, see the built-in function in Chapter 6.
###Input format:
The first line represents the number of lines entered
In the following line, enter a string representing a vertex, the edge connected to the vertex, and the length
###Output format:
Output the number of vertices, the number of edges and the total length of edges in a row
###Input example:
Here is a set of inputs. For example:
```in
four
{'a':{'b':10,'c':6}}
{'b':{'c':2,'d':7}}
{'c':{'d':10}}
{'d':{}}
```
###Output example:
The corresponding output is given here. For example:
```out
4 5 35
```
answer:If there is no answer, please comment
```
n=int(input())
vertex=0
edge=0
length=0
for i in range(n):
l=input()
d=eval(l)
for key1 in d:
vertex+=1
for key2 in d[key1]:
edge+=1
length+=d[key1][key2]
print(vertex,edge,length)
```
Dictionary representation of graphs. Input multiple lines of string, each line represents a vertex and its connected edge and length, output vertex number, edge number, total length of edge. For example, point 0 in the figure above shows:
{'O':{'A':2,'B':5,'C':4}}。 Use the eval function to process the input. For the specific usage of the eval function, see the built-in function in Chapter 6.
###Input format:
The first line represents the number of lines entered
In the following line, enter a string representing a vertex, the edge connected to the vertex, and the length
###Output format:
Output the number of vertices, the number of edges and the total length of edges in a row
###Input example:
Here is a set of inputs. For example:
```in
four
{'a':{'b':10,'c':6}}
{'b':{'c':2,'d':7}}
{'c':{'d':10}}
{'d':{}}
```
###Output example:
The corresponding output is given here. For example:
```out
4 5 35
```
answer:If there is no answer, please comment
```
n=int(input())
vertex=0
edge=0
length=0
for i in range(n):
l=input()
d=eval(l)
for key1 in d:
vertex+=1
for key2 in d[key1]:
edge+=1
length+=d[key1][key2]
print(vertex,edge,length)
```