#P14503. [NCPC 2025] Instagraph

[NCPC 2025] Instagraph

题目描述

:::align{center} :::

A celebrity in a social network is somebody with many followers, but who doesn't follow them back. More precisely, a person is a celebrity\emph{celebrity} for a group of people, if

  • every member of the group follows the person,
  • the person follows nobody in the group.

The celebrity centrality\emph{celebrity centrality} of person vv, written CC(v)\mathrm{CC}(v), is the maximum size of such a group.

We model the social network as a directed graph with NN vertices 11, \ldots, NN. A directed edge from uu to vv means that person uu follows person vv. For example, in

:::align{center} :::

we have CC(1)=0\operatorname{CC}(1) = 0, CC(2)=1\operatorname{CC}(2) = 1, and CC(5)=2\operatorname{CC}(5) = 2.

Your task is to find a vertex vv with the maximum celebrity centrality CC(v)\mathrm{CC}(v). In case of a tie, choose the smallest vv.

输入格式

The input consists of

  • One line with two integers NN and MM (1N2000001 \le N \le 200\,000, 0M10000000 \le M \le 1\,000\,000), the number of vertices and the number of directed edges.
  • MM lines with two distinct integers uu and vv (1u,vN1 \le u,v \le N), indicating a directed edge from uu to vv. There are no duplicate edges.

输出格式

Output two integers: the smallest vv with the maximum celebrity centrality and the value CC(v)\mathrm{CC}(v).

6 8
1 2
2 1
2 3
3 2
3 6
4 5
5 2
6 5
5 2
1 0
1 0