結果

問題 No.2428 Returning Shuffle
ユーザー kt_soupkt_soup
提出日時 2023-08-18 21:41:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 71,932 KB
実行使用メモリ 20,744 KB
最終ジャッジ日時 2024-05-06 03:36:45
合計ジャッジ時間 5,601 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int par(int x,vector<int>& p) {
  if(x == p[x])return x;
  else return p[x] = par(p[x],p);
}

long long gcd(long long a,long long b) {
  if(b)return gcd(b,a%b);
  else return a;
}

int main() {
  int N,M,t;
  cin >> N >> M;
  vector<int> p(N);
  for(int i=0;i<N;i++)p[i] = i;
  for(int i=0;i<M;i++) {
    cin >> t;
    vector<int> s(t),pp = p;
    for(int j=0;j<t;j++)cin >> s[j];
    for(int j=0;j<t;j++)p[s[(j+1)%t]-1] = pp[s[j]-1];
  }
  
  vector<int> pa(N),c(N,0);
  for(int i=0;i<N;i++)pa[i] = i;
  for(int i=0;i<N;i++)pa[par(i,pa)] = par(p[i],pa);
  for(int i=0;i<N;i++)c[par(i,pa)]++;
  long long ans = 1;
  for(int i=0;i<N;i++)if(c[i])ans = ans*c[i]/gcd(ans,c[i]);
  cout << ans << endl;
}
0