浙大19年保研上机之 Index of Popularity

                                                 Index of Popularity

The index of popularity (IP) of someone in his/her circle of friends is defined to be the number of friends he/she has in that circle. Now you are supposed to list the members in any given friend circle with top 3 IP's.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 2 positive integers N and M (both no more than 10​5​​), which are the total number of people and the number of friend relations, respectively. Hence the people here are numbered from 1 to N.

Then M lines follow, each contains the indices of a pair of friends, separated by a space. It is assumed that if A is a friend of B, then B is a friend of A.

Then several queries follow, each occupies a line. For each line of query, K (3≤K≤N), the total number of members in this friend circle is given first, with K indices of members follow. It is guaranteed that all the indices in a circle are distinct.

The input ends when K is zero, and this case must NOT be processed.

Output Specification:

For each query, print in a line the members with top 3 indices of popularity in descending order of their IP's. If there is a tie, output the one with the smaller number. The numbers must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.

Sample Input:

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

Sample Output:

3 1 4
1 3 2
2 4 7
#include 
#include
using namespace std;
struct Edge
{
    int u,v;
};
vector edge;
int n,m;
struct Node
{
    int v,cnt;
};
bool vis[100001]={false};
bool cmp(Node a,Node b)
{
    if(a.cnt!=b.cnt)
        return a.cnt>b.cnt;
    else
        return a.v>n>>m;
    int a,b,k,e;
    for(int i=0;i>a>>b;
        edge.push_back({a,b});
    }
    while(1)
    {
        fill(vis,vis+100001,false);
        cin>>k;
        if(k==0)
            break;
        set s;
        vector ans;
        for(int i=0;i>e;
            ans.push_back({e,0});
            s.insert(e);
        }
        map M;
        for(int i=0;i ::iterator it=M.begin();it!=M.end();it++)
        {
            ans.push_back({it->first,it->second});
        }
        sort(ans.begin(),ans.end(),cmp);
            for(int i=0;i<3;i++)
            {
                cout<

 

你可能感兴趣的:(pat)