Friends

시간 제한1초메모리 제한2048 MB

요약
무향 친구 관계 그래프와 내 사용자 번호가 주어질 때, 친구 관계가 전이적이라는 규칙 아래 내가 모든 사용자와 친구인지 판정한다.
난이도

쉬움10점 중 3점

유형
그래프, 유니온 파인드, DFS
정답자
아직 제출이 없습니다

문제

A new social network has been released and as you're very into new technology, you immediately decide to join it. After creating your account, you would look who has joined the network already so you can send some friend requests. It appears this is not a regular social network like Facebook and there's one difference: when you are friends with someone, you're automatically friends with all the people he or she is also friends with. For example, if you're friends with "Jan", and "Jan" is friends with "Piet", then you are also friends with "Piet" and all other people he has as friend.

You are given the details of the network. You know which members have joined the network and which users are friends with each other. Each user has an unique identifier in the network.

More and more people are joining the new established network and you would like to know whether you're friends with everyone. After all, one can never have too much friends on a social network!

입력

The first line consists of the integers nn, mm and ss (1≤n≤10001 \leq n \leq 1000 , 0≤m≤250000 \leq m \leq 25000 , 0≤s≤10000 \leq s \leq 1000): nn is the amount of registered users in the network, mm denotes the number of connections in the network and ss is your user identifier. After that, mm lines follow with on each line two integers: aa and bb which means that users with identifiers aa and bb are friends in the network.

출력

One line with either yesyes if you have every other user as a friend or nono if not.

예제2

  1. 예제 1

    입력
    5 4 3
    0 1
    1 2
    2 3
    3 4
    
    예상 출력
    yes
    
  2. 예제 2

    입력
    6 3 2
    1 2
    1 4
    0 5
    
    예상 출력
    no