Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:我的过了2969ms……

Posted by sunyiping01 at 2019-04-24 21:30:50 on Problem 3013
In Reply To:我的过了2969ms…… Posted by:karlgeorge at 2017-04-20 23:46:06
> //我的过了
> #include<iostream>
> #include<cstdio>
> #include<cstring>
> #include<algorithm>
> #include<queue>
> #include<functional>
> 
> using namespace std;
> typedef long long ll;
> typedef pair<ll,ll> P;
> 
> const ll maxn=50000+10;
> const ll inf=1e15;
> 
> ll e,v;
> 
> vector<P> G[maxn];
> ll w[maxn];
> ll d[maxn];
> 
> void init(){
>     for(ll i=0;i<=v;++i)
>         d[i]=inf;
>     d[1]=0;
> }
> 
> void dij(){
>     priority_queue<P,vector<P>,greater<P> > q;
>     q.push(make_pair(0,1));
>     while(!q.empty()){
>         ll now=q.top().second;
>         q.pop();
>         for(ll i=0;i<G[now].size();++i){
>             ll t=G[now][i].first;
>             if(d[t]>d[now]+G[now][i].second){
>                 d[t]=d[now]+G[now][i].second;
>                 q.push(make_pair(d[t],t));
>             }
>         }
>     }
> }
> 
> int main(){
>     ios_base::sync_with_stdio(0);
>     cin.tie(0);
>     ll T;
>     cin>>T;
>     while(T--){
>         memset(d,0,sizeof(d));
>         cin>>v>>e;
>         for(ll i=1;i<=v;++i){
>             cin>>w[i];
>             G[i].clear();
>         }
>         init();
>         for(ll i=1;i<=e;++i){
>             ll a,b,c;
>             cin>>a>>b>>c;
>             G[a].push_back(make_pair(b,c));
>             G[b].push_back(make_pair(a,c));
>         }
>         dij();
>         ll ans=0;
>         bool flag=false;
>         for(ll i=2;i<=v;++i){
>             ans+=(d[i]*w[i]);
>             if(d[i]>=inf){
>                 flag=true;
>                 break;
>             }
>         }
>         if(flag){
>             cout<<"No Answer"<<endl;
>             continue;
>         }
>         cout<<ans<<endl;
>     }
>     return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator