Problem 2686 --Graph I - Graph

2686: Graph I - Graph

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $2$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签 STL

Graph 

There are two standard ways to represent a graph G=(V,E), where V is a set of vertices and E is a set of edges; Adjacency list representation and Adjacency matrix representation. 

An adjacency-list representation consists of an array Adj[|V|] of |V| lists, one for each vertex in V. For each u∈V, the adjacency list Adj[u] contains all vertices v such that there is an edge (u,v)∈E. That is, Adj[u] consists of all vertices adjacent to u in G. 

An adjacency-matrix representation consists of |V|×|V| matrix A=aij  such that aij=1 if (i,j)∈E, aij=0 otherwise. 

Write a program which reads a directed graph G represented by the adjacency list, and prints its adjacency-matrix representation. G consists of n(=|V|) vertices identified by their IDs 1,2,..,nrespectively.

In the first line, an integer n is given. In the next n lines, an adjacency list Adj[u] for vertex u are given in the following format: 

u k v1 v2 ... vk 

u is vertex ID and k denotes its degree. vi are IDs of vertices adjacent to u.

As shown in the following sample output, print the adjacent-matrix representation of G. Put a single space character between aij.
4
1 2 2 4
2 1 4
3 0
4 1 3
0 1 0 1
0 0 0 1
0 0 0 0
0 0 1 0
1≤ n≤ 100

推荐代码 查看2686 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] 刘成健 334696 2018-11-30 19:15:20
内存最少[$2020 $KB] 刘成健 334696 2018-11-30 19:15:20
第一AC 刘成健 334696 2018-11-30 19:15:20
第一挑战 刘成健 334696 2018-11-30 19:15:20

赛题来源/所属竞赛 会津大学《挑战数据结构与算法》 挑战数据结构与算法

竞赛编号 竞赛名称 竞赛时间 访问比赛