-->
当前位置:首页 > 题库

PROGRAMMING:The creation of graph

Luz5年前 (2021-05-10)题库367
Write a program to create a directed graph. A digraph contains n vertices, numbered from 0 to n-1.
###Input format:
Enter two positive integers n and E in the first line to represent the number of vertices and edges of the graph, where n does not exceed 20000 and E does not exceed 1000. Next, line e represents the information of each edge, and each line contains three non negative integers a, B, and C, where a and B represent the endpoint number of the edge, and C represents the weight. The sides are not arranged in end numbered order.
###Output format:
Output the leading edge of each vertex in ascending order according to vertex number, and each vertex occupies one line. If a vertex has no leading edge, it will not be output. Each line represents all the edges led out by a vertex, with the format of a: (a, B, w)..., indicating that the weight of a - > b is w, and the edges led out by a are arranged in the increasing order of number B.
###Input example:
```in
7 7
0 1 5
0 3 7
0 6 6
1 2 4
2 5 1
3 5 3
6 5 4
```
###Output example:
```out
0:(0,1,5)(0,3,7)(0,6,6)
1:(1,2,4)
2:(2,5,1)
3:(3,5,3)
6:(6,5,4)
```







answer:If there is no answer, please comment