HDU 6026 Deleting Edges

最短路。

先建一个只包含最短路的有向无环图,每一个点选择任意一条入边即可生成一个树形图,那么树的种类就等于每个点的入度乘积。

#include <bits/stdc++.h>
using namespace std;

const long long mod = 1e9+7;
int n;
char s[60][60];
int dis[60],f[60];
int in[60];

void spfa()
{
    queue<int>Q;
    for(int i=0;i<n;i++) f[i]=0,dis[i] = 0x7FFFFFFF;
    dis[0]=0; Q.push(0); f[0]=1;

    while(!Q.empty())
    {
        int h = Q.front(); Q.pop(); f[h]=0;
        for(int i=0;i<n;i++)
        {
            int val = s[h][i]-‘0‘;
            int to = i;
            if(val==0) continue;
            if(dis[h]+val<dis[to])
            {
                dis[to] = dis[h]+val;
                if(f[to]==0)
                {
                    f[to]=1;
                    Q.push(to);
                }
            }
        }
    }
}

int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++) scanf("%s",s[i]);
        spfa();

        memset(in,0,sizeof in);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i==j) continue;
                int val = s[i][j]-‘0‘;
                if(val==0) continue;
                if(dis[i]+val == dis[j])
                {
                    in[j]++;
                }
            }
        }

        long long ans=1;

        for(int i=0;i<n;i++)
        {
            if(in[i]==0) continue;
            ans = ans* (long long)in[i]%mod;
        }

        printf("%lld\n",ans);

    }
    return 0;
}
时间: 2024-10-05 12:14:47

HDU 6026 Deleting Edges的相关文章

hdu 6026 Deleting Edges 江苏徐州邀请赛K

Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1693    Accepted Submission(s): 575 Problem Description Little Q is crazy about graph theory, and now he creates a game about gra

2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

Deleting Edges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 567    Accepted Submission(s): 210 Problem Description Little Q is crazy about graph theory, and now he creates a game about grap

hdu 4496 D-City 并查集

D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2317    Accepted Submission(s): 814 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-

hdu 4496 并查集 反向并查集 水题 D-City

觉得这道题以后可以和优先队列结合起来 嗯 就是说依次去掉前n条路求连通块数量 处理的时候  只要每次merge发现父亲不相等 然后进到里面合并的时候 num-- wa了好几次是因为最后输出的时候开了点的数量大小的数组而不是操作数量数组 orz D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 5334    Accepted

BNUOJ 33895 D-City

D-City Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged on HDU. Original ID: 449664-bit integer IO format: %I64d      Java class name: Main Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city. D-

hdu4496 D-City(反向并查集)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496 D-City Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D

Hdoj 4496 D-City 【并查集】

D-City Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2134 Accepted Submission(s): 751 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city.

杭电4496--D-City(***并查集***)

D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2649    Accepted Submission(s): 922 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-c

HDU4496_D-City(并查集删边/逆向)

D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1315    Accepted Submission(s): 496 Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to D-