标签:ret alt 程序设计 please cin nal 学生 cti i++
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1693 Accepted Submission(s): 575
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; string s[100]; int mp[100][100],n; int dis[100],vis[100],in_[100]; struct node{ int to,v; friend bool operator < (node a,node b){return a.v<b.v;}; friend bool operator > (node a,node b){return a.v>b.v;}; }; void dij(){ priority_queue<node,vector<node>,greater<node> >q; memset(dis,0x3f,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[0]=0;vis[0]=1;q.push({0,0}); while(!q.empty()){ node u=q.top();q.pop(); if(u.v>dis[u.to]) continue; for(int i=0;i<n;i++){ if(mp[u.to][i]==0) continue; if(dis[i]>dis[u.to]+mp[u.to][i]){ dis[i]=dis[u.to]+mp[u.to][i]; q.push({i,dis[i]}); } } } } int main(){ while(cin>>n){ for(int i=0;i<n;i++) cin>>s[i]; memset(in_,0,sizeof(in_)); for(int i=0;i<n;i++) for(int j=0;j<n;j++) mp[i][j]=s[i][j]-‘0‘; dij(); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(mp[i][j]==0) continue; if(dis[i]+mp[i][j]==dis[j]) in_[j]++; } } long long ans=1; for(int i=1;i<n;i++){ if(in_[i])(ans*=in_[i])%=mod; } printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; string s[100]; int mp[100][100],n; int dis[100],vis[100],in_[100]; void dij(){ //priority_queue<int,vector<int>,greater<int> >q; queue<int>q; memset(dis,0x3f,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[0]=0;vis[0]=1;q.push(0); while(!q.empty()){ int u=q.front();q.pop();vis[u]=0; for(int i=0;i<n;i++){ if(mp[u][i]==0) continue; if(dis[i]>dis[u]+mp[u][i]){ dis[i]=dis[u]+mp[u][i]; if(!vis[i]){ q.push(i); vis[i]=1; } } } } } int main(){ while(cin>>n){ for(int i=0;i<n;i++) cin>>s[i]; memset(in_,0,sizeof(in_)); for(int i=0;i<n;i++) for(int j=0;j<n;j++) mp[i][j]=s[i][j]-‘0‘; dij(); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(mp[i][j]==0) continue; if(dis[i]+mp[i][j]==dis[j]) in_[j]++; } } long long ans=1; for(int i=1;i<n;i++){ if(in_[i])(ans*=in_[i])%=mod; } printf("%lld\n",ans); } return 0; }
hdu 6026 Deleting Edges 江苏徐州邀请赛K
标签:ret alt 程序设计 please cin nal 学生 cti i++
原文地址:https://www.cnblogs.com/vainglory/p/9142280.html