結果
問題 | No.614 壊れたキャンパス |
ユーザー |
![]() |
提出日時 | 2017-12-14 01:08:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 860 ms / 2,000 ms |
コード長 | 2,317 bytes |
コンパイル時間 | 1,888 ms |
コンパイル使用メモリ | 181,504 KB |
実行使用メモリ | 71,112 KB |
最終ジャッジ日時 | 2024-12-14 10:43:48 |
合計ジャッジ時間 | 11,539 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:44:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 44 | scanf("%d%d%d%d%d",&n,&m,&k,&s,&t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:45:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | REP(i,m)scanf("%d%d%d",a+i,b+i,c+i); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef vector<int> vi;typedef vector<ll> vl;typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef int _loop_int;#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)#define DEBUG(x) cout<<#x<<": "<<x<<endl#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl#define ALL(a) (a).begin(),(a).end()#define CHMIN(a,b) a=min((a),(b))#define CHMAX(a,b) a=max((a),(b))// modconst ll MOD = 1000000007ll;#define FIX(a) ((a)%MOD+MOD)%MOD// floatingtypedef double Real;const Real EPS = 1e-11;#define EQ0(x) (abs(x)<EPS)#define EQ(a,b) (abs(a-b)<EPS)typedef complex<Real> P;int n,m,k,s,t;int a[252521], b[252521], c[252521];vi po[252521];map<pii,int> vrtx;vector<pii> g[425252];ll dist[425252];int main(){scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);REP(i,m)scanf("%d%d%d",a+i,b+i,c+i);po[0].push_back(s);po[n-1].push_back(t);REP(i,m){a[i]--;po[a[i]].push_back(b[i]);po[a[i]+1].push_back(c[i]);}int it = 0;REP(i,n){sort(ALL(po[i]));po[i].erase(unique(ALL(po[i])), po[i].end());REP(j,po[i].size()){vrtx[pii(i,po[i][j])] = it++;}REP(j,po[i].size()-1){int from = vrtx[pii(i,po[i][j])];int to = vrtx[pii(i,po[i][j+1])];int sa = po[i][j+1] - po[i][j];g[from].push_back(pii(to,sa));g[to].push_back(pii(from,sa));}}REP(i,m){int from = vrtx[pii(a[i], b[i])];int to = vrtx[pii(a[i]+1, c[i])];g[from].push_back(pii(to,0));}const ll INF = 1e18;REP(i,it)dist[i] = INF;priority_queue<pll> Q;int start = vrtx[pii(0,s)];dist[start] = 0ll;Q.push(pll(-dist[start], start));while(!Q.empty()){ll d = Q.top().first;int pos = Q.top().second; Q.pop();if(dist[pos] != -d)continue;for(pii P : g[pos]){int to = P.first;int cost = P.second;if(dist[pos] + cost < dist[to]){dist[to] = dist[pos] + cost;Q.push(pll(-dist[to], to));}}}int goal = vrtx[pii(n-1,t)];if(dist[goal] == INF){dist[goal] = -1;}cout<<dist[goal]<<endl;return 0;}