結果

問題 No.92 逃走経路
ユーザー motxxmotxx
提出日時 2014-12-07 21:58:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,110 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 163,048 KB
実行使用メモリ 35,488 KB
最終ジャッジ日時 2023-09-02 10:59:35
合計ジャッジ時間 9,127 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 404 ms
5,952 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
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;
typedef int ll;

ll const INF = 1<<29;

struct EDGE {
  ll u, v, c;
  EDGE(ll u=0, ll v=0, ll c=INF) : u(u), v(v), c(c)
  {}
  bool operator < (EDGE const& e) const {
    return c < e.c;
  }
};

struct Edge {
  ll to, cost;
};

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

Graph g;
vector<ll> d;
bool vlistb[1100][110];
ll N, M, K;
vector<vector<EDGE> > v;

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

void dfs(int idx, ll depth) {
  if(memo[idx][depth]) return;
  if(depth == K) {
    if(!ansb[idx]) ansc++, ansb[idx] = 1;
    //    ans.insert(idx);
    return ;
  }
  memo[idx][depth] = 1;
  rep(i, g[idx].size()) {
    Edge& e = g[idx][i];
    if(!vlistb[depth][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) {
    ll 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());
  es.push_back(EDGE(0,0,INF));
  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);
    }
  }
  
  rep(i, K) {
    rep(j, v[i].size()) {
      vlistb[i][v[i][j].u] = 1;
      vlistb[i][v[i][j].v] = 1;
      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});
    }
  }
  
  rep(i, N) {
    if(vlistb[0][i]) { dfs(i, 0); }
  }
  
  cout << ansc << endl;
  //cout << ans.size() << endl;
  bool f = 0;
  rep(i, N) {
    if(!ansb[i]) continue;
    if(f) cout << " ";
    f = 1;
    cout << i+1;
  }
  cout << endl;
  
  return 0;
}
0