Ways to set a graph


Plus
Pin


Problem description Progress
ID 33471. Vertex degrees
Темы: Ways to set a graph   

An undirected graph is defined by an adjacency matrix. Find the degrees of all the vertices of the graph.

Input:
- the first line contains the number n\(1 \leq n \leq 100\)) – number of vertices in the graph;
- followed by n lines of n numbers, each equal to 0 or 1, – its adjacency matrix.

Output: output n numbers – degrees of graph vertices (one number per line).

 

Examples
# Input Output
1 5
0 0 1 0 0 
0 0 1 0 1 
1 1 0 0 0 
0 0 0 0 0 
0 1 0 0 0 
1
2
2
0
1

ID 38632. Mockery
Темы: Ways to set a graph    Simple puzzles   

Stirlitz was driving a car, saw Bormann voting, and drove past. After a while, he again saw Bormann voting, and again drove past. Soon he saw Bormann voting again.
 - scoffs! thought Bormann.
 - Ring! - Stirlitz guessed.


There are N squares in the city. Any two squares are connected to each other by exactly one two-way road. Stirlitz lives in this city. Stirlitz has a hobby - he likes to leave the house on Sunday mornings, get into the car, choose some ring route that passes exactly three squares (that is, first he goes from some square to some other, then to the third , then returns to the initial one, and again travels along this route). He imagines that Bormann is somewhere along the way. And so Stirlitz drives all Sunday, until his head is spinning, and rejoices...

Naturally, Stirlitz wants to drive past the point where, as he imagines, Bormann is standing, as often as possible. To do this, of course, the route chosen by Stirlitz should be as short as possible. Write a program that will choose the optimal route for Stirlitz.

Input
The first line specifies  number N (3 <= N <= 100). The following lines contain a matrix of NxN distances between squares (the number in position i,j denotes the length of the road connecting the i-th and j-th squares). All numbers in the matrix (except for those on the main diagonal) are natural numbers, not exceeding 1000. The matrix is ​​symmetrical with respect to the main diagonal, there are 0 on the main diagonal.

Imprint
It is required to print three numbers — numbers of areas in the optimal route. If there are several routes, print any of them.

Examples
# Input Output
1 5
0 1 9 9 2
1 0 9 9 9
9 9 0 9 9
9 9 9 0 9
2 9 9 9 0
1 2 5

ID 44035. Road map
Темы: Ways to set a graph   

Santa Claus draws up a road map that will allow you to visit N cities in the shortest possible time. For simplicity, he numbered all cities with numbers 1,..., N. Cities are connected by M number of roads. Ith road (1<=i<=M) connects city Ai and city Bi. Before building the optimal route, Santa Claus wants to know which cities each city is associated with. Help Santa Claus.
Output N lines as follows.

  • Let di be the number of cities directly related to city i (1<=i<=N) and these cities will be cities ai,1, ..., ai,di listed in ascending order.
  • Ith line (1<=i<=N) should contain di+1 integer: di, ai,1,..., ai,di in that order, separated by spaces.

Input
The first line of the input contains two integers separated by one space N and M (2 <= N <= 105,  1 <= M <= 105). M lines follow, each containing 2 numbers Ai and Bi (1 <= Ai <Bi <= N, 1 <= i <= M).
If ij then (AiBi )(AjBj). All numbers are integers.

Imprint
Output N lines according to the format described in the problem statement.
 
 
Examples
# Input Output
1 6 6
36
1 3
5 6
25
1 2
16
3 2 3 6
2 1 5
2 1 6
0
2 2 6
3 1 3 5
2 5 10
1 2
1 3
14
15
23
24
25
34
3 5
4 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4