美文网首页
PATA1076-Forwads On Weibo

PATA1076-Forwads On Weibo

作者: crishawy | 来源:发表于2019-03-11 10:17 被阅读0次

题目描述

1076 Forwards on Weibo (30 分)
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can view and forward his/her post, which can then be forwarded again by their followers. Now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only L levels of indirect followers are counted.

Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤1000), the number of users; and L (≤6), the number of levels of indirect followers that are counted. Hence it is assumed that all the users are numbered from 1 to N. Then N lines follow, each in the format:

M[i] user_list[i]
where M[i] (≤100) is the total number of people that user[i] follows; and user_list[i] is a list of the M[i] users that followed by user[i]. It is guaranteed that no one can follow oneself. All the numbers are separated by a space.

Then finally a positive K is given, followed by K UserID's for query.

Output Specification:
For each UserID, you are supposed to print in one line the maximum potential amount of forwards this user can trigger, assuming that everyone who can view the initial post will forward it once, and that only L levels of indirect followers are counted.

Sample Input:
7 3
3 2 3 4
0
2 5 6
2 3 1
2 3 4
1 4
1 5
2 2 6
Sample Output:
4
5

参考代码

#include<cstdio>
#include<queue>
#include<cstring>

using namespace std;
const int maxn = 1010;

int L,N;
int G[maxn][maxn] = {0};
//bool vis[maxn] = {false};
struct node
{
    //顶点编号和层号
    int v,layer;
    node(int _v,int _layer):v(_v),layer(_layer){}
};

void BFS(int u,int& sum,bool inq[])
{
    queue<node> Q;
    Q.push(node(u,0));
    inq[u] = true;
    while(!Q.empty())
    {
        node top = Q.front();
        Q.pop();
        //printf("第%d层,正在访问%d\n",top.layer,top.v);
        //vis[top] = true;
        //如果在规定的层内
        if(top.layer<L)
            for(int i=1;i<=N;i++)
            {
                if(G[i][top.v]>0  && inq[i] == false)
                {
                    Q.push(node(i,top.layer+1));
                    inq[i] = true;
                    sum ++;
                    //printf("第%d层,sum=%d\n",top.layer,sum);
                }
            }
    }
}

int main()
{
    bool mid[maxn] = {false};
    bool inq[maxn] = {false};
    scanf("%d %d",&N,&L);
    int k,temp;
    for(int i=0;i<N;i++)
    {
        scanf("%d",&k);
        for(int j=0;j<k;j++)
        {
            scanf("%d",&temp);
            G[i+1][temp] = 1;
        }
    }
    scanf("%d",&k);
    for(int i=0;i<k;i++)
    {
        scanf("%d",&temp);
        int sum=0;
        BFS(temp,sum,inq);
        printf("%d\n",sum);
        //数组赋值
        memcpy(inq,mid,maxn*sizeof(bool));
    }

}






相关文章

  • PATA1076-Forwads On Weibo

    题目描述 1076 Forwards on Weibo (30 分)Weibo is known as the C...

  • 转weibo

    什么样的人算是独立的人? 知乎上的一个回答是:一个人有自己的价值观并能根据自己的价值观做出人生选择,并且言行一致能...

  • Weibo 2017.6.25

    我最近总是有一个很恐怖的想法 烦躁的时候就预谋着怎么自杀 虽然很蠢 说出来很傻逼 但是我说出来的原因是我微博没有...

  • Weibo Is Not Trustworthy

    Starting 2010, Weibo has become a news reader and note-ta...

  • 关于weibo

    卸掉weibo有一点失落,像是告别了自己的爱情,总是习惯性想去打开它,其实并没有什么好看的有趣的,里面变得全是八卦...

  • weibo崩了

    已经刷不出任何新动态了,不知道什么时候能恢复正常。 好不容易过了半个小时终于能刷出动态了,还没正常五分钟又崩了。不...

  • 【转载】信息安全走向漫谈

    https://weibo.com/p/1001603959419229573350[https://weibo....

  • 错误信息:bridging header '/Users

    bridging header '/Users/wyl/Desktop/WeiBo/WeiBo/Classes/H...

  • python ajax weibo

    import requests from urllib.parse import urlencode from p...

  • repo from weibo

    [爱一个人就像在树荫下走路。光斑与阴影,温暖与凉意,交错在一起,复杂地落在肩头与后背。伤害与爱并行。 伤害很痛,但...

网友评论

      本文标题:PATA1076-Forwads On Weibo

      本文链接:https://www.haomeiwen.com/subject/qvlvpqtx.html