結果

問題 No.92 逃走経路
ユーザー motxxmotxx
提出日時 2014-12-07 21:29:52
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,988 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 170,220 KB
実行使用メモリ 9,116 KB
最終ジャッジ日時 2023-09-02 10:40:31
合計ジャッジ時間 9,951 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 880 ms
9,116 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

struct EDGE {
  int u, v, c;
  bool operator < (EDGE const& e) const {
    return c < e.c;
  }
};

struct Edge {
  int to, cost;
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int const INF = 1<<29;

Graph g;
vector<int> d;
vector<set<int> > vlist;
int N, M, K;
vector<vector<EDGE> > v;

set<int> ans;
bool memo[110][1100];  //[idx][depth]
vector<EDGE> es;

void dfs(int idx, int depth) {
  if(memo[idx][depth]) return;
  if(depth == K) {
    ans.insert(idx);
    return ;
  }
  memo[idx][depth] = 1;
  rep(i, g[idx].size()) {
    Edge& e = g[idx][i];
    if(!vlist[depth].count(e.to)) continue;
    if(d[depth] != e.cost) continue;
    dfs(e.to, depth+1);
  }
}

int main() {
  
  cin >> N >> M >> K;
  es.resize(M);
  g.resize(N+1);
  rep(i, M) {
    int a, b, c; cin >> a >> b >> c; a--, b--;
    es[i].u = a, es[i].v = b, es[i].c = c;
  }
  
  d.resize(K);
  rep(i, K) cin >> d[i];

  sort(es.begin(), es.end());
  v.resize(K);
  rep(i, K) {
    auto uiter = upper_bound(es.begin(), es.end(), (EDGE){0,0,d[i]});
    auto liter = lower_bound(es.begin(), es.end(), (EDGE){0,0,d[i]});
    
    for(auto iter=liter; iter!=uiter; iter++) {
      v[i].push_back(*iter);
    }
  }
  
  vlist.resize(K);
  rep(i, K) {
    rep(j, v[i].size()) {
      vlist[i].insert(v[i][j].u);
      vlist[i].insert(v[i][j].v);
      g[v[i][j].u].push_back((Edge){v[i][j].v, v[i][j].c});
      g[v[i][j].v].push_back((Edge){v[i][j].u, v[i][j].c});
    }
  }

  for(auto iter = vlist[0].begin(); iter!=vlist[0].end(); iter++) {
    dfs(*iter, 0);
  }
  
  cout << ans.size() << endl;
  bool f = 0;
  for(auto iter = ans.begin(); iter!=ans.end(); iter++) {
    if(f) cout << " ";
    f = 1;
    cout << (*iter)+1;
  }
  cout << endl;
  
  return 0;
}
0