結果

問題 No.1190 Points
ユーザー snow39snow39
提出日時 2020-08-22 16:59:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 103,472 KB
実行使用メモリ 20,008 KB
最終ジャッジ日時 2023-08-05 13:53:57
合計ジャッジ時間 4,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 58 ms
15,248 KB
testcase_04 AC 48 ms
14,100 KB
testcase_05 AC 44 ms
12,912 KB
testcase_06 AC 75 ms
18,296 KB
testcase_07 AC 88 ms
19,688 KB
testcase_08 AC 88 ms
19,984 KB
testcase_09 AC 89 ms
18,160 KB
testcase_10 AC 93 ms
20,008 KB
testcase_11 AC 61 ms
14,140 KB
testcase_12 AC 94 ms
19,536 KB
testcase_13 AC 54 ms
12,096 KB
testcase_14 AC 24 ms
13,068 KB
testcase_15 AC 110 ms
19,356 KB
testcase_16 AC 12 ms
6,452 KB
testcase_17 AC 98 ms
18,708 KB
testcase_18 AC 36 ms
7,492 KB
testcase_19 AC 27 ms
16,524 KB
testcase_20 AC 46 ms
9,884 KB
testcase_21 AC 27 ms
10,688 KB
testcase_22 AC 39 ms
16,916 KB
testcase_23 AC 110 ms
19,840 KB
testcase_24 AC 104 ms
19,836 KB
testcase_25 AC 79 ms
19,344 KB
testcase_26 AC 58 ms
19,156 KB
testcase_27 AC 81 ms
19,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

vector<vector<int>> g;
const int INF=1e9;

void bfs(int st,vector<vector<int>> &dist){
  queue<pair<int,int>> Q;
  Q.push(mkp(st,0));
  dist[st][0]=0;
  while(!Q.empty()){
    auto f=Q.front();
    Q.pop();
    int now=f.first;
    int pr=f.second;

    for(auto nex:g[now]){
      if(dist[nex][pr^1]<INF) continue;
      dist[nex][pr^1]=dist[now][pr]+1;
      Q.push(mkp(nex,pr^1));
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,M,P;
  cin>>N>>M>>P;
  int S,G;
  cin>>S>>G;
  S--;G--;
  g.resize(N);
  rep(i,M){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<vector<int>> sdist(N,vector<int> (2,INF));
  vector<vector<int>> gdist(N,vector<int> (2,INF));
  bfs(S,sdist);
  bfs(G,gdist);

  vector<int> ans;
  for(int i=0;i<N;i++){
    if(P%2){
      if(sdist[i][0]+gdist[i][1]<=P||sdist[i][1]+gdist[i][0]<=P) ans.push_back(i);
    }else{
      if(sdist[i][0]+gdist[i][0]<=P||sdist[i][1]+gdist[i][1]<=P) ans.push_back(i);
    }
  }

  if(ans.size()==0) cout<<-1<<"\n";
  else{
    cout<<ans.size()<<"\n";
    for(auto n:ans) cout<<n+1<<"\n";
  }


  return 0;
}
0