Counting Pairs
Time limit4sMemory limit256 MB
Given an undirected multigraph with self-loops, count pairs of vertices whose combined incident-edge count exceeds k for each of up to 10^6 queries.
- Level
Hard8 of 10
- Topics
- Graph, Sorting, Prefix sum, Two pointers
- Solved
- No attempts yet
Problem
You are given an undirected graph with vertices, numbered from to , and edges.
Consider a pair of vertices with . The incidence of is the total number of edges that have at least one endpoint equal to or .
You have to answer queries. Each query gives an integer and asks how many pairs of vertices in satisfy and have incidence strictly greater than .
Input
The first line contains two integers and , the number of vertices and the number of edges ().
The next lines follow. The -th of them contains two integers and , the endpoints of the -th edge (). There may be self-loops or parallel edges.
The next line contains one integer , the number of queries ().
The next lines follow. The -th of them contains an integer , the -th query ().
Output
For each query, print a single line with a single integer: the answer to the query.