Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}//-1で初期化
  int root(int x) {
    if (d[x] < 0) return x;//rootを負にする（構成node数x(-1))
    //root以外は親の番号
    return d[x] = root(d[x]);
    //return(root(d[x]))とするとメモできないが上の書き方だとメモができる
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    //swapすることで小さい方を大きい方につけられ計算量減らせる
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  //同じグループ化
  int size(int x) { return -d[root(x)];}
  //グループのnode数
    int group_num(int n){
        set<int> s;
        for(int i = 0; i < n; ++i){
            s.insert(root(i));
        }
        return int(s.size());}
};



// Morris-Pratt
template<typename T>
struct MP {
  int n;
  T t;
  vector<int> a;
  MP() {}
  MP(const T& t): t(t) {
    n = t.size();
    a = vector<int>(n+1);//便宜上最初に-1を入れるため（1 indexにした方が良い)
    a[0] = -1;
    int j = -1;
    for (int i = 0; i < n; ++i) {
      while (j != -1 && t[j] != t[i]) j = a[j];//次の文字が一致するようなaを見つける
      j++;
      a[i+1] = j;
    }
  }
  int operator[](int i) { return a[i];}//添字アクセスできるように
  vector<int> findAll(const T& s) {
    vector<int> res;
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      while (j != -1 && t[j] != s[i]) j = a[j];
      j++;
      if (j == n) {
        res.push_back(i-j+1);
        j = a[j];
      }
    }
    return res;
  }
};

/*使用例

int main(){
string t,s;
cin>>t;
MP mp(t);
cin>>s;
vector<int> ans=mp.findAll(s);
}
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  vector<int> xa = f(a);
  vector<int> xb = f(b);
  MP<vector<int>> mp(xa);
  xb.insert(xb.end(), xb.begin(), xb.end());
  vector<int> res = mp.findAll(xb);
  vector<int> ks;
  for (int p : res) ks.push_back(n-p);
  sort(ks.begin(), ks.end());
  for (int k : ks) {
    if (k >= n) continue;
    int x = a[k]^b[0];
    printf("%d %d\n", k, x);
  }
  return 0;
}
*/




int main() {
  string s,t,sn;
  cin>>s>>t;
  sn=s;
  sn+=s;
  sn+=s;

  while(sn.size()<=t.size()*2){
    sn=sn+sn;
  }
//  cout<<sn<<endl;
  ll T=t.size();
  ll S=s.size();
  MP <string> mp(t);
  vector<ll> v(S+1,0);
//  cout<<sn.size()<<endl;
  vector<ll> id=mp.findAll(sn);
  rep(i,id.size()){
    //cout<<id[i]<<endl;
    v[id[i]%S]=1;
//    cout<<id[i]%S<<endl;
  }
ll ans=0;
  UnionFind uf(S);
  //vector<int> used(500005,0);
  rep(i,S){
  //  cout<<now<<'n'<<used[now]<<'u'<<endl;
    if (v[i]!=1)continue;
    if (v[(i+T)%S]==1){
      if (uf.same(i,(i+T)%S)){
      //  cout<<now%S<<' '<<(now+T)%S;
        cout<<-1;
        return 0;
      }
      else{
      //  cout<<i<<' '<<(i+T)%S;
        uf.unite(i,(i+T)%S);
      //  used[i]=1;
      //  cout<<uf.size(now)<<endl;
        ans=max(ans,uf.size(i));
      }
    }
  }

cout<<ans;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:125:27: error: conversion from 'vector<int>' to non-scalar type 'vector<long long int>' requested
  125 |   vector<ll> id=mp.findAll(sn);
      |                 ~~~~~~~~~~^~~~
a.cc:148:16: error: no matching function for call to 'max(ll&, int)'
  148 |         ans=max(ans,uf.size(i));
      |             ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:148:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  148 |         ans=max(ans,uf.size(i));
      |             ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:148:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  148 |         ans=max(ans,uf.size(i));
      |             ~~~^~~~~~~~~~~~~~~~