結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2015-04-21 15:40:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 5,000 ms |
| コード長 | 1,114 bytes |
| コンパイル時間 | 1,929 ms |
| コンパイル使用メモリ | 164,860 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 19:07:18 |
| 合計ジャッジ時間 | 2,390 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘void rec(int, int)’:
main.cpp:18:25: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
18 | } else if(!dp[idx][cnt]++) {
| ~~~~~~~~~~~^
main.cpp: In function ‘int main()’:
main.cpp:52:10: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
52 | if(first++) cout << " ";
| ^~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, cost;
};
typedef vector< vector< edge > > Graph;
int N, M, K;
Graph graph;
int val[1000];
bool visited[100], dp[1000][1000];
void rec(int idx, int cnt)
{
if(cnt == K) {
visited[idx] = true;
} else if(!dp[idx][cnt]++) {
for(int i = 0; i < graph[idx].size(); i++) {
edge& e = graph[idx][i];
if(val[cnt] == e.cost) rec(e.to, cnt + 1);
}
}
}
int main()
{
fill_n( *dp, 1000 * 1000, false);
cin >> N >> M >> K;
graph.resize(N);
for(int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
graph[a].push_back((edge){b, c});
graph[b].push_back((edge){a, c});
}
for(int i = 0; i < K; i++) {
cin >> val[i];
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < graph[i].size(); j++) {
edge&e = graph[i][j];
if(val[0] == e.cost) rec(i, 1);
}
}
cout << count(visited, visited + N, true) << endl;
bool first = false;
for(int i = 0; i < N; i++) {
if(visited[i]) {
if(first++) cout << " ";
cout << i + 1;
}
}
cout << endl;
}
ei1333333