結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-16 03:24:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 5,000 ms |
| コード長 | 1,900 bytes |
| コンパイル時間 | 296 ms |
| コンパイル使用メモリ | 39,296 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 23:03:49 |
| 合計ジャッジ時間 | 1,376 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d %d %d %d", &N, &M, &S, &G);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:54:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <vector>
class counter_iterator{
private:
int count;
public:
counter_iterator() : count(0){}
counter_iterator(int n) : count(n){}
bool operator==(const counter_iterator& rhs) const{
return count == rhs.count;
}
bool operator!=(const counter_iterator& rhs) const{
return count != rhs.count;
}
int& operator*(){
return count;
}
counter_iterator& operator++(){
++count;
return *this;
}
};
class loop{
private:
int b, e;
public:
loop(int m) : b(0), e(m){}
loop(int n, int m) : b(n), e(m){}
counter_iterator begin() const{
return counter_iterator(b);
}
counter_iterator end() const{
return counter_iterator(e);
}
};
int d[200][200], d2[200][200];
int main(){
int N, M, S, G;
scanf("%d %d %d %d", &N, &M, &S, &G);
for(int i : loop(0, N)){
for(int j : loop(0, N)){
d[i][j] = i == j ? 0 : 1001001001;
d2[i][j] = i == j ? 0 : 1001001001;
}
}
for(int i=0;i<M;i++){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
d[a][b] = c;
d[b][a] = c;
d2[a][b] = c;
d2[b][a] = c;
}
for(int k : loop(0, N)){
for(int i : loop(0, N)){
for(int j : loop(0, N)){
d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
}
}
}
std::vector<int> route{S};
int v = S, prev_v = -1;
while(v != G){
for(int i : loop(0, N)){
if(i == v || i == prev_v){continue;}
if(d[S][v] + d2[v][i] + d[i][G] == d[S][G]){
route.push_back(i);
prev_v = v;
v = i;
break;
}
}
}
for(int i : loop(0, route.size())){
printf("%d%c", route[i], i==route.size()-1?'\n':' ');
}
}
tottoripaper