Submission #00365
ソースコード
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #include <bits/stdc++.h> #define REP(i,a,b) for(int i=(a);i<(b);i++) #define RREP(i,a,b) for(int i=(a);i>=(b);i--) #define pq priority_queue #define P pair<ll,ll> #define P2 pair<int,P> #define P3 pair<int,P2> typedef long long ll; typedef long double ld; using namespace std; const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0}; const ll LINF=1e18; const ld PI= abs ( acos (-1)); int n,m,a,b,v,u; ll w; ll lia[100010]={},lib[100010]={},li[100010]; vector<P> g[100010]; set< int > sta; ll dijkstra( int s, int t, bool f){ ll min_cost[100010]={}; ll mi=LINF; pq<P, vector<P>, greater<P>> que; REP(i,0,n) min_cost[i]=LINF; que.emplace(0,s); min_cost[s]=0; while (!que.empty()){ auto p=que.top(); que.pop(); if (p.first>min_cost[p.second]) continue ; for (auto e:g[p.second]){ if (p.first+e.second>=min_cost[e.first]) continue ; min_cost[e.first]=p.first+e.second; if (sta.count(e.first)) mi=min(mi,min_cost[e.first]); que.emplace(min_cost[e.first], e.first); } } return (f?mi:min_cost[t]); } ll find( int s, bool f){ ll min_cost[100010]={}; pq<P, vector<P>, greater<P>> que; REP(i,0,n) min_cost[i]=LINF; que.emplace(0,s); min_cost[s]=0; while (!que.empty()){ auto p=que.top(); que.pop(); if (p.first>min_cost[p.second]) continue ; for (auto e:g[p.second]){ if (p.first+e.second>=min_cost[e.first]) continue ; min_cost[e.first]=p.first+e.second; que.emplace(min_cost[e.first], e.first); } } if (f) REP(i,0,n) lia[i]=min_cost[i]; else REP(i,0,n) lib[i]=min_cost[i]; return 0; } int make( int s){ ll min_cost[100010]={}; pq<P, vector<P>, greater<P>> que; REP(i,0,n) min_cost[i]=LINF; que.emplace(0,s); min_cost[s]=0; while (!que.empty()){ auto p=que.top(); que.pop(); li[p.second]=min(li[p.second], p.first); if (p.first>min_cost[p.second]) continue ; for (auto e:g[p.second]){ if (p.first+e.second>=min_cost[e.first]) continue ; min_cost[e.first]=p.first+e.second; que.emplace(min_cost[e.first], e.first); } } return 0; } int main(){ cin >> n >> m >> a >> b; a--; b--; REP(i,0,m){ scanf ( "%d %d %lld" ,&v,&u,&w); g[u-1].push_back(P(v-1,w)); g[v-1].push_back(P(u-1,w)); } ll s=0; bool f= true ; set< int > vv; find(a,1); find(b,0); ll minc=lia[b]; REP(i,0,n) if (minc==lia[i]+lib[i]) sta.insert(i); REP(i,0,n) li[i]=LINF; for (auto s:sta) make(s); REP(i,0,n) s+=li[i]; cout << s << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0004 - railway |
ユーザー名 | Noel |
投稿日時 | 2017-11-26 14:53:31 |
言語 | C++11 |
状態 | Time Limit Exceeded |
得点 | 20 |
ソースコード長 | 2491 Byte |
最大実行時間 | 1000 ms |
最大メモリ使用量 | 18568 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 80 | * |
2 | partial_1 | 20 / 20 | !*, *S* |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | |
---|---|---|---|---|---|
!test01.txt | AC | 14 ms | 5344 KB |
1
|
2
|
!test02.txt | AC | 15 ms | 5320 KB |
1
|
2
|
mesh_01.txt | AC | 71 ms | 14364 KB |
1
|
|
mesh_02.txt | AC | 70 ms | 14236 KB |
1
|
|
randomL_01.txt | AC | 689 ms | 18528 KB |
1
|
|
randomL_02.txt | AC | 628 ms | 18416 KB |
1
|
|
randomL_03.txt | AC | 715 ms | 18552 KB |
1
|
|
randomL_04.txt | AC | 508 ms | 18568 KB |
1
|
|
randomL_05.txt | AC | 478 ms | 18504 KB |
1
|
|
randomS_01.txt | AC | 21 ms | 5440 KB |
1
|
2
|
randomS_02.txt | AC | 17 ms | 5524 KB |
1
|
2
|
randomS_03.txt | AC | 17 ms | 5612 KB |
1
|
2
|
treeL_01.txt | TLE | 1000 ms | 11212 KB |
1
|
|
treeL_02.txt | TLE | 1000 ms | 11200 KB |
1
|
|
treeS_01.txt | AC | 24 ms | 5432 KB |
1
|
2
|
treeS_02.txt | AC | 25 ms | 5480 KB |
1
|
2
|