結果

問題 No.160 最短経路のうち辞書順最小
ユーザー なお
提出日時 2015-03-01 23:44:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,157 bytes
コンパイル時間 1,824 ms
コンパイル使用メモリ 171,780 KB
最終ジャッジ日時 2024-06-24 00:42:08
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/usr/bin/ld: /tmp/ccnTyn5C.o: warning: relocation against `_ZN8DijkstraIiE3infE' in read-only section `.text.startup'
/usr/bin/ld: /tmp/ccnTyn5C.o: in function `main':
main.cpp:(.text.startup+0x1f0): undefined reference to `Dijkstra<int>::inf'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i))
#define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i))
#define mp make_pair
#define pb push_back
const int MOD = int(1e9+7);
int N,M,S,G;
int res = 0;
int g[222][222];
template <class _Tc>
class Dijkstra {
public:
static const int inf = 1<<29;
int m_num;
vector<vector<pair<int,_Tc> > > m;
void init(int n){
m_num = n;
m.clear();
m.resize(n);
}
void add(int u, int v, _Tc e){
m[u].pb(mp(v,e));
}
_Tc solve(int u, int v, vector<_Tc> *pcost = NULL, vector<int> *proute = NULL){
int n = m_num;
vector<_Tc> c(n, inf);
vector<int> r(n, -1);
priority_queue<pair<_Tc,int> > q;
c[u] = 0;
q.push(mp(0, u));
while(!q.empty()){
int u = q.top().second; q.pop();
FOREACH(it,m[u]){
int v = it->first;
_Tc nc = c[u] + it->second;
if(c[v] > nc || (c[v] == nc && (r[v] == -1 || r[v] > u))){
c[v] = nc; r[v] = u;
q.push(mp(-nc,v));
}
}
}
if(pcost) *pcost = c;
if(proute) *proute = r;
return c[v];
}
};
int main(){
do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);
cin >> N >> M >> S >> G;
Dijkstra<int> d;
d.init(N);
REP(i,M){
int a,b,c;
cin >> a >> b >> c;
d.add(a,b,c);
d.add(b,a,c);
}
VI route;
d.solve(S, G, NULL, &route);
VI rt;
int i = G;
while(i != S){
rt.pb(i);
i = route[i];
}
reverse(rt.begin(), rt.end());
int n = rt.size();
cout << S;
REP(i,n) cout << " " << rt[i];
cout << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0