結果

問題 No.1775 Love Triangle 2
ユーザー PCTprobabilityPCTprobability
提出日時 2021-12-05 12:31:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,372 bytes
コンパイル時間 4,527 ms
コンパイル使用メモリ 275,444 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-07 07:34:17
合計ジャッジ時間 718,819 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7,826 ms
6,812 KB
testcase_01 AC 7,829 ms
6,940 KB
testcase_02 AC 7,827 ms
6,940 KB
testcase_03 AC 7,828 ms
6,940 KB
testcase_04 AC 7,832 ms
6,940 KB
testcase_05 AC 7,826 ms
6,944 KB
testcase_06 AC 7,831 ms
6,944 KB
testcase_07 AC 7,825 ms
6,940 KB
testcase_08 AC 7,827 ms
6,944 KB
testcase_09 AC 7,830 ms
6,944 KB
testcase_10 AC 7,913 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 7,828 ms
6,944 KB
testcase_13 AC 7,835 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 7,839 ms
6,944 KB
testcase_18 WA -
testcase_19 AC 7,827 ms
6,944 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 7,825 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 7,827 ms
6,944 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 7,828 ms
6,944 KB
testcase_37 AC 7,824 ms
6,940 KB
testcase_38 AC 7,826 ms
6,940 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 7,830 ms
6,944 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 7,832 ms
6,944 KB
testcase_69 AC 7,826 ms
6,940 KB
testcase_70 AC 7,827 ms
6,948 KB
testcase_71 AC 7,830 ms
6,944 KB
testcase_72 AC 7,829 ms
6,940 KB
testcase_73 AC 7,829 ms
6,940 KB
testcase_74 AC 7,837 ms
6,944 KB
testcase_75 AC 7,826 ms
6,940 KB
testcase_76 AC 7,826 ms
6,940 KB
testcase_77 AC 7,827 ms
6,940 KB
testcase_78 AC 7,832 ms
6,940 KB
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 AC 7,832 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define endl "\n"
typedef pair<int,int> Pii;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define PB push_back
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(s) (s).begin(),(s).end()
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define pb push_back
#define P pair<ll,ll>
#define PQminll priority_queue<ll, vector<ll>, greater<ll>>
#define PQmaxll priority_queue<ll,vector<ll>,less<ll>>
#define PQminP priority_queue<P, vector<P>, greater<P>>
#define PQmaxP priority_queue<P,vector<P>,less<P>>
#define NP next_permutation
typedef string::const_iterator State;
class ParseError {};
//const ll mod = 1000000009;
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 4100000000000000000ll;
const ld eps = ld(0.00000000000001);
//static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T>void print(T a){cout<<a<<endl;}
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}

void cincout() {
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
}
vector<ll> g[200];
ll now=-1;
bool seen[200],finish[200];
stack<ll> v;
void dfs(ll a,ll b){
  seen[a]=true;
  v.push(a);
  for(auto e:g[a]){
    if(e==b) continue;
    if(finish[e]) continue;
    if(seen[e]){
      now=e;
      return;
    }
    dfs(e,a);
    if(now!=-1) return;
  }
  v.pop();
  finish[a]=true;
}
int main() {
  cincout();
  ll n,m;
  cin>>n>>m;
  ll x,y,z;
  cin>>x>>y>>z;
  x--;
  y--;
  z--;
  vector<vector<ll>> f(n,vector<ll>(n,1));
  for(int i=0;i<m;i++){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    f[a][b]=f[b][a]=0;
  }
  ll ans=inf;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j&&f[i][j]) g[i].pb(j);
    }
  }
  while(clock()/1000<7800){
    std::random_device seed_gen;
    std::mt19937 engine(seed_gen());
    for(int i=0;i<n;i++){
      std::shuffle(all(g[i]),engine);
    }
    now=-1;
    for(int i=0;i<n;i++){
      seen[i]=finish[i]=false;
    }
    dfs(x,-1);
    vector<bool> cyc(n,false);
    while(!v.empty()){
      ll t=v.top();
      cyc[t]=true;
      v.pop();
      if(t==now) break;
    }
    while(!v.empty()) v.pop();
    ll si=0;
    for(auto e:cyc) if(e) si++;
    if(cyc[x]&&cyc[y]&&cyc[z]) chmin(ans,si);
  }
  if(ans>inf/2) ans=-1;
  cout<<ans<<endl;
}
0