시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 128 MB88161319.118%

문제

강원도 횡성에는 엄청나게 큰 나무 두 개가 마주보고 있다. 이 나무의 기둥에는 수많은 구멍들이 있고, 수많은 딱따구리들이 이 구멍에서 서식하기 위해 몰려들었다. 하나의 구멍에는 한 마리의 딱따구리만이 서식할 수 있고 비어있는 구멍도 있을 수 있다. 이들 중 몇몇 두 딱따구리는 친밀한 관계를 유지하여 이들의 서식지를 왔다 갔다 한다. 하지만 딱따구리는 워낙 빨리 이동하기 때문에 충돌의 위험을 줄이기 위해 몇몇 규칙으로 딱따구리의 서식지를 배정하려 한다.

  1. 딱따구리의 이동경로는 직선이다.
  2. 친밀한 관계를 가지는 두 딱따구리는 서로 다른 나무에 서식하고 있어야한다.
  3. 친밀한 관계를 가지는 딱따구리의 서식지를 연결하는 선분끼리 교차하면 안 된다. 단, 끝점 즉 서식지는 공유해도 상관없다

딱따구리는 가능한 한 낮은 곳에 위치한 구멍에서 서식하기를 원한다. 또한 각각의 나무에 있는 구멍의 수는 딱따구리의 수보다 크다. 문제는 이러한 조건을 만족하는 서식지 배정의 가짓수를 구하는 것이다.

입력

첫째 줄에 새들의 숫자를 나타내는 N(1 ≤ N ≤ 1,000,000), 친밀한 관계를 유지하는 딱따구리 쌍의 수를 나타내는 M(1 ≤ M ≤ 10,000,000), 결과를 나눌 제수 K(1 ≤ K ≤ 2,000,000)가 공백으로 구분되어 주어진다. 새들은 1번부터 N번까지 번호가 붙여져 있고 두 번째 줄부터 M+1번째 줄까지 각 줄에 친밀한 관계를 가지는 딱따구리의 번호가 공백으로 구분되어 주어진다.

출력

첫째 줄에 서식지 배정의 가짓수 R을 K로 나눈 나머지를 출력한다. 서식지를 배정할 수 없는 경우는 0을 출력한다.

예제 입력 1

3 2 10
1 2
1 3

예제 출력 1

4

힌트

W3sicHJvYmxlbV9pZCI6IjE2NDIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI1MzFcdWI1MzBc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