Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #python 3.7.1
- from collections import OrderedDict
- m, n = map(int, input().split())
- references = [list(map(int, input().split())) for _ in range(n)]
- link={}
- for a, b in references:
- if a not in link.keys():
- link[a] = set()
- if b not in link.keys():
- link[b] = set()
- link[a].add(b)
- link[b].add(a)
- blogs = list(map(int, input().split()))
- topicBlog = {}
- stack=OrderedDict()
- for blog, topic in enumerate(blogs):
- blog+=1
- if topic not in topicBlog.keys():
- topicBlog[topic] = []
- topicBlog[topic].append(blog)
- topicBlog=sorted(topicBlog.items(), key=lambda x:x[0])
- flag=True
- for topic, blogs in topicBlog:
- for blog in blogs:
- desired=list(range(1,topic))
- if blog not in link.keys():
- link[blog]=set()
- for neighbor in link[blog]:
- if neighbor in stack.keys():
- if stack[neighbor]==topic:
- print(-1)
- flag=False
- break
- if stack[neighbor] in desired:
- desired.remove(stack[neighbor])
- if flag==False:
- break
- if len(desired)!=0:
- print(-1)
- flag=False
- break
- stack[blog] = topic
- if flag==False:
- break
- if flag==True:
- print(' '.join([str(i) for i in stack]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement