记录编号 |
581337 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[Nescafé II]黑暗城堡 |
最终得分 |
100 |
用户昵称 |
┭┮﹏┭┮ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.213 s |
提交时间 |
2023-08-01 15:35:47 |
内存使用 |
9.76 MiB |
显示代码纯文本
- #include <bits/stdc++.h>
- using namespace std;
- typedef pair<int,int> P;
- const int N = 1010,M = 2000010;
- const long long mod = (1LL << 31) - 1;
- long long ans = 1;
- int n,m,a[N][N];
- struct made{
- int ver,ed,nx;
- }e[M];
- int hd[N],tot,d[N],k;
- bool v[N];
- void init();
- void add_(int x,int y,int z);
- void dij(int x){
- memset(v,0,sizeof(v));
- memset(d,0x3f,sizeof(d));
- priority_queue<P,vector<P>,greater<P> >q;
- d[x] = 0;
- q.push(make_pair(d[x],x));
- while(!q.empty()){
- int x = q.top().second;q.pop();
- if(v[x])continue;
- v[x] = 1;
- for(int i = hd[x];i;i = e[i].nx){
- int y = e[i].ver,z = e[i].ed;
- if(d[x] + z < d[y]){
- d[y] = d[x] + z;
- q.push(make_pair(d[y],y));
- }
- }
- }
- }//dij堆优化
- void prim(){
- memset(v,0,sizeof(v));
- v[1] = 1,ans = 1;
- for(int i = 1;i < n;i++){
- int x = 0;k = 0;
- for(int j = 2;j <= n;j++)
- if(!v[j] && (!x || d[j] < d[x]))x = j;
- for(int y = 1;y <= n;y++){
- if(v[y] && d[y] + a[y][x] == d[x])k++;//该节点有几种方案
- }
- v[x] = 1;
- ans = 1LL * ans * k % mod;//乘法原理求方案数
- //类似prim求方案数
- }
- }
- int main(){
- freopen("darkcastle.in","r",stdin);
- freopen("darkcastle.out","w",stdout);
- init();
- dij(1);
- prim();
- printf("%lld\n",ans);
-
- return 0;
-
- }
- void add_(int x,int y,int z){
- tot++;
- e[tot].ver = y,e[tot].ed = z,e[tot].nx = hd[x],hd[x] = tot;
- }
- void init(){
- memset(a,0x3f,sizeof(a));
- scanf("%d%d",&n,&m);
- for(int i = 1;i <= m;i++){
- int x,y,z;
- scanf("%d%d%d",&x,&y,&z);
- a[x][y] = min(z,a[x][y]);
- a[y][x] = min(z,a[y][x]);
- add_(x,y,z);
- add_(y,x,z);
- }
- for(int i = 1;i <= n;i++)a[i][i] = 0;
- }
-
-