我是靠谱客的博主 傻傻乐曲,这篇文章主要介绍2018ACM-ICPC 江苏站 K.Road链接来源题解代码,现在分享给大家,希望可以做个参考。

链接

https://www.jisuanke.com/contest/1408?view=challenges

来源

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest

题解

没做过图上的计数问题qwq
单源最短路的路径数可能不止一条,就是说从 1 1 i可能有多条最短路
把这些最短路径提取出来,可以形成一个有向无环图,从 1 1 走到每个点有多条路径,但是这些路径长度都等于原图中从1 i i 的最短路
你只要求出生成树的个数即可,注意这里是有向树,而且保证必须从1能走到 i i <script type="math/tex" id="MathJax-Element-7">i</script>。
看了题解,发现是这样考虑
每个点肯定都要有一个父亲节点,所以统计每个点的入度,然后相乘即可。

代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//图论 #include <cstdio> #include <algorithm> #include <cctype> #include <cstring> #define maxn 110 #define inf 0x3f3f3f3f #define cl(x,y) memset(x,y,sizeof(x)) #define ll long long #define mod 1000000007ll using namespace std; int f[maxn][maxn], dist[maxn][maxn], n, cnt[maxn]; int readdigit() { char c; for(c=getchar();!isdigit(c);c=getchar()); return (int)(c-48); } void floyd() { int i, j, k; for(i=1;i<=n;i++)for(j=1;j<=n;j++)f[i][j]=dist[i][j]; for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)f[i][j]=min(f[i][j],f[i][k]+f[k][j]); } void init() { int i, j; for(i=1;i<=n;i++)for(j=1;j<=n;j++) { dist[i][j]=readdigit(); if(!dist[i][j])dist[i][j]=inf; if(i==j)dist[i][j]=0; } cl(cnt,0); } void work() { int i, j; ll ans=1; floyd(); for(i=2;i<=n;i++)for(j=1;j<=n;j++)if(i!=j and f[1][i]==f[1][j]+dist[j][i])cnt[i]++; for(i=2;i<=n;i++)ans=ans*cnt[i]%mod; printf("%lldn",ans); } int main() { while(~scanf("%d",&n))init(), work(); return 0; }

最后

以上就是傻傻乐曲最近收集整理的关于2018ACM-ICPC 江苏站 K.Road链接来源题解代码的全部内容,更多相关2018ACM-ICPC内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(121)

评论列表共有 0 条评论

立即
投稿
返回
顶部