結果

問題 No.92 逃走経路
ユーザー ei1333333ei1333333
提出日時 2015-04-21 15:40:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,114 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 150,436 KB
実行使用メモリ 4,668 KB
最終ジャッジ日時 2023-09-18 02:17:49
合計ジャッジ時間 3,049 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,648 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,612 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 6 ms
4,504 KB
testcase_07 AC 6 ms
4,400 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,668 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 12 ms
4,396 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 6 ms
4,424 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,412 KB
testcase_19 AC 6 ms
4,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void rec(int, int)’:
main.cpp:18:26: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
   } else if(!dp[idx][cnt]++) {
                          ^~
main.cpp: In function ‘int main()’:
main.cpp:52:15: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
       if(first++) cout << " ";
               ^~

ソースコード

diff #

#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;
}
0