시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
10 초 128 MB 24 5 5 23.810%

문제

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

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

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

입력

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

출력

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

예제 입력 1

3 2 10
1 2
1 3

예제 출력 1

4

힌트

W3sicHJvYmxlbV9pZCI6IjE2NDIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWI1MzFcdWI1MzBcdWFkNm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