zoukankan      html  css  js  c++  java
  • 第二次周赛 friend

    Problem Description
    Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than k friends in common, they will become friends in several days. Currently, there are totally n people in the country, and m friendship among them. Assume that any new friendship is made only when they have sufficient friends in common mentioned above, you are to tell how many new friendship are made after a sufficiently long time.

    Input

    There are multiple test cases.

    The first lien of the input contains an integer T (about 100) indicating the number of test cases. Then T cases follow. For each case, the first line contains three integers n, m, k (1 ≤ n ≤ 100, 0 ≤ mn×(n-1)/2, 0 ≤ kn, there will be no duplicated friendship) followed by m lines showing the current friendship. The ith friendship contains two integers ui, vi (0 ≤ ui, vi < n, ui ≠ vi) indicating there is friendship between person ui and vi.

    Note: The edges in test data are generated randomly.

    Output

    For each case, print one line containing the answer.

    Sample Input

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

    Sample Output

    2
    0
    4
    #include<iostream>
    #include<string.h>
    #include<vector>
    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<algorithm>
    #define INF 10000000
    using namespace std;
    vector <int > g[102];
    
    
    int vis[102],d[102],p[102],w[102][102],rank[102];//w[a][b]  a到b的 优惠(为  - )
    void spfa(int s,int n)
    {
        int i;
        for(i=1;i<=n;i++)
            d[i]=INF;
        d[s]=10000;
        memset(vis,0,sizeof(vis));
        queue<int > q;
        q.push (s); vis[s]=1;
        while(!q.empty ())
        {
            int a,b;
            a=q.front (); q.pop ();
            for(i=0;i<g[a].size ();i++)
            {
                b=g[a][i];
                if(d[b]>d[a]+w[a][b])
                {
                    d[b]=d[a]+w[a][b];
                    if(!vis[b])
                    {
                        vis[b]=1;
                        q.push (b);
                    }
                }
            }
        }
    }
    
    
    int main()
    {
        int i,j,m,n,p[102],rank[102],x,a,b;
        while(scanf("%d%d",&m,&n)!=EOF)
        {
            memset(w,0,sizeof(w));   //    一定会有优惠  即w一定会《0
            for(i=1;i<=n;i++)
            {
                scanf("%d%d%d",&p[i],&rank[i],&x);
                while(x--)
                {
                    scanf("%d%d",&a,&b);
                    w[i][a]=b-p[i];      //a  i优惠的金币  为-
                }
            }
            for(i=1;i<=n;i++)
                for(j=1;j<=n;j++)
                {
                    if(abs(rank[i]-rank[j])<=m&&w[i][j]!=0)
                    {
                        w[i][j]+=p[j];
                        g[i].push_back (j);
                    }
                }
                /*for(i=1;i<=n;i++)
                {
                    printf("%d    ",i);
                    for(j=0;j<g[a].size ();j++)
                        printf("%d ",g[a][j]);
                    printf("
    ");
                }*/
    
    
             spfa(1,n);
             //for(i=1;i<=n;i++)
            //     printf("%d  d %d
    ",i,d[i]);
             int minn=INF;
             for(i=1;i<=n;i++)
                 if(minn>d[i])
                     minn=d[i];
                 if(minn<0)
                     minn=0;
            printf("%d
    ",minn);
        }
        return 0;
    }
  • 相关阅读:
    spring cloud 专题二(spring cloud 入门搭建 之 微服务搭建和注册)
    spring cloud 专题一 (spring cloud 入门搭建 之 Eureka注册中心搭建)
    mysql存储过程查询结果循环遍历 判断 赋值 游标等基本操作
    Jquery datatable 动态隐藏列(根据有无值)
    spring boot无法启动,或者正常启动之后无法访问报404的解决办法
    通过js给网页加上水印背景
    jdk动态代理原理
    关于loadrunner使用web_add_header添加HTTP信息头(比如Content-Type,token等)和使用
    IP路由及静态路由配置
    安装ie时,报:此安装不支持您的操作系统的当前语言
  • 原文地址:https://www.cnblogs.com/assult/p/3221147.html
Copyright © 2011-2022 走看看