标签:directed auto cto set training row from ber hose
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6166
题目:
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 245 Accepted Submission(s): 71
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define MP make_pair 6 #define PB push_back 7 typedef long long LL; 8 typedef pair<int,int> PII; 9 const double eps=1e-8; 10 const double pi=acos(-1.0); 11 const int K=1e5+7; 12 const int mod=1e9+7; 13 14 vector<PII >mp[K]; 15 vector<int>key,st,se; 16 LL dis[K]; 17 int n,m,k; 18 19 LL spfa(vector<int> &s,vector<int> &e) 20 { 21 queue<int>q; 22 fill(dis+1,dis+n+1,1e12); 23 for(auto &x:s) 24 q.push(x),dis[x]=0; 25 while(q.size()) 26 { 27 int u=q.front();q.pop(); 28 for(auto &v:mp[u]) 29 if(dis[v.first]>dis[u]+v.second) 30 { 31 dis[v.first]=dis[u]+v.second; 32 q.push(v.first); 33 } 34 } 35 LL ret=1e15; 36 for(auto &x:e) 37 ret=min(ret,dis[x]); 38 return ret; 39 } 40 int main(void) 41 { 42 //freopen("in.acm","r",stdin); 43 int t,cs=1;cin>>t; 44 while(t--) 45 { 46 memset(mp,0,sizeof mp); 47 key.clear(); 48 LL ans=1e15; 49 scanf("%d%d",&n,&m); 50 for(int i=1,x,y,z;i<=m;i++) 51 scanf("%d%d%d",&x,&y,&z),mp[x].PB(MP(y,z)); 52 scanf("%d",&k); 53 for(int i=1,x;i<=k;i++) 54 scanf("%d",&x),key.PB(x); 55 for(int i=0;i<=20;i++) 56 { 57 st.clear(),se.clear(); 58 for(auto &x:key) 59 if(x&(1<<i)) 60 st.push_back(x); 61 else 62 se.push_back(x); 63 ans=min(ans,min(spfa(st,se),spfa(se,st))); 64 } 65 printf("Case #%d: %lld\n",cs++,ans); 66 } 67 return 0; 68 }
标签:directed auto cto set training row from ber hose
原文地址:http://www.cnblogs.com/weeping/p/7413926.html