結果

問題 No.1190 Points
ユーザー snow39snow39
提出日時 2020-08-22 16:59:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 104,688 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-04-23 11:05:10
合計ジャッジ時間 3,949 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 48 ms
15,488 KB
testcase_04 AC 40 ms
14,208 KB
testcase_05 AC 36 ms
13,056 KB
testcase_06 AC 60 ms
18,688 KB
testcase_07 AC 65 ms
19,704 KB
testcase_08 AC 64 ms
20,096 KB
testcase_09 AC 67 ms
18,304 KB
testcase_10 AC 69 ms
20,096 KB
testcase_11 AC 47 ms
14,208 KB
testcase_12 AC 69 ms
19,496 KB
testcase_13 AC 44 ms
12,160 KB
testcase_14 AC 20 ms
13,440 KB
testcase_15 AC 78 ms
19,584 KB
testcase_16 AC 11 ms
6,400 KB
testcase_17 AC 72 ms
18,944 KB
testcase_18 AC 32 ms
7,680 KB
testcase_19 AC 21 ms
16,640 KB
testcase_20 AC 40 ms
10,112 KB
testcase_21 AC 22 ms
10,752 KB
testcase_22 AC 31 ms
17,280 KB
testcase_23 AC 82 ms
19,968 KB
testcase_24 AC 83 ms
19,968 KB
testcase_25 AC 62 ms
19,584 KB
testcase_26 AC 46 ms
19,328 KB
testcase_27 AC 59 ms
19,584 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