Submit | All submissions | Best solutions | Back to list |
TPCPPLAR - Popular |
English | Vietnamese |
Given a directed graph G, N vertices and M edges.
A node X called "accessible" to Y if there is a path from X to Y
A node X called "popular" if every node Y in V fulfil at least one of two conditions:
- X is accessible to Y
- Y is accessible to X
The Problem: Given graph G, count the number of popular nodes.
Input
- The first line contain N and M, the number of nodes and edges (1 ≤ N ≤ 150000; 1 ≤ M ≤ 300000)
- M next lines, each line contains x and y, there is an edge from x to y.
Output
- First line print number of popular nodes.
- Second line print popular nodes in increasing order.
Example
Input: 5 4 1 2 3 2 2 4 4 5 Output: 3 2 4 5
Added by: | Mew. |
Date: | 2014-09-18 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
hide comments
2023-03-22 04:57:34 Oleg
Clarification: "fulfil one of two conditions" should be read as " fulfil at least one of two conditions". |