AcWing 1523. 学生课程列表
原题链接
中等
作者:
aac
,
2024-11-22 14:34:01
,
所有人可见
,
阅读 1
from collections import defaultdict
mp = defaultdict(list)
n,k = map(int,input().split())
for i in range(k):
course_id,Ni = map(int,input().split())
for x in input().split():
mp[x].append(course_id)
for x in input().split():
# print(x,end='')
# print(f' {len(mp[x])}',end = '')
# li = mp[x]
# li.sort()
# for y in li:
# print(f' {y}',end = '')
# print()
# 这两种写法完全等价,但下面这种更加优雅
mp[x].sort()
if x in mp:
print(x,len(mp[x]),*mp[x])
else:
print(x,0)