結果

問題 No.92 逃走経路
ユーザー motxxmotxx
提出日時 2014-12-07 20:23:03
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,461 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 168,572 KB
実行使用メモリ 38,108 KB
最終ジャッジ日時 2023-09-02 09:43:48
合計ジャッジ時間 10,257 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 707 ms
7,004 KB
testcase_14 RE -
testcase_15 AC 1,651 ms
10,096 KB
testcase_16 AC 1,181 ms
9,320 KB
testcase_17 RE -
testcase_18 AC 959 ms
6,196 KB
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

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 u, v, c;
  int to, cost;
  /*
  bool operator < (Edge const& e) const {
    return c < e.c;
  }
  */
};

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;

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

void dfs(int idx, int depth) {
  //  cerr << idx << endl;
  if(memo[idx][depth]) return;
  if(depth == K) {
    //    cerr << "inserted: " << idx << endl;
    ans.insert(idx);
  }
  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;
  vector<EDGE> es(M);
  g.resize(N);
  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;
    
    //g[a].push_back((Edge){b, c});
    //g[b].push_back((Edge){a, c});
  }
  
  d.resize(K);
  rep(i, K) cin >> d[i];

  sort(es.begin(), es.end());
  vector<vector<EDGE> > v(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);
  //  set<pair<int, int> > st;
  rep(i, K) {
    rep(j, v[i].size()) {
      vlist[i].insert(v[i][j].u);
      vlist[i].insert(v[i][j].v);
      //vlist[i].push_back(v[i][j].u);
      //vlist[i].push_back(v[i][j].v);
      //      if(!st.count(make_pair(v[i][j].u, 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});
    }
    /*
    sort(vlist[i].begin(), vlist[i].end());
    vlist[i].erase(unique(vlist[i].begin(), vlist[i].end()), vlist[i].end());
    */
  }
  
  for(auto e: vlist[0]) {
    dfs(e, 0);
    //  cerr << "---\n";
  }
  
  cout << ans.size() << endl;
  bool f = 0;
  for(auto e: ans) {
    if(f) cout << " ";
    f = 1;
    cout << e+1;
  }
  cout << endl;
  
  return 0;
}
0