結果

問題 No.1190 Points
ユーザー snow39
提出日時 2020-08-22 16:59:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 1,229 ms
コンパイル使用メモリ 104,580 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-10-15 11:00:34
合計ジャッジ時間 4,649 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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