比赛 2022级数学专题练习赛6 评测结果 AAAAAAAAAA
题目名称 庆典的日期 最终得分 100
用户昵称 op_组撒头屯 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-01-23 22:00:59
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200+5;
const ll inf=0x3f3f3f3f3f3f;
int n,m;
int p[N][N],tmp[N];
int tot=0;
int to[N],id[N],pos[N];
vector<int>v[N];
bool vis[N]={0};
void dfs(int pt){
	id[pt]=tot;v[tot].push_back(pt);
	pos[pt]=v[tot].size()-1;vis[pt]=1;
	if (!vis[to[pt]])dfs(to[pt]);
}
ll gcd(ll x,ll y){
    if (!y)return x;
    return gcd(y,x%y);
}
ll solve(){
    for (int i=1;i<=n;i++){
        int now=i;
        for (int j=1;j<=m;j++){
            now=p[now][j];
        }
        to[i]=now;
    }
    tot=0;memset(vis,0,sizeof(vis));
    for (int i=1;i<=n;i++){
		if (!vis[i])tot++,dfs(i);
	}ll ans=1;
	for (int i=1;i<=n;i++){
		ll cnt=v[id[i]].size();
		ans=ans*cnt/gcd(ans,cnt);
		if (ans*m>9000000)return ans;
	}
	for (int i=1;i<=tot;i++)v[i].clear();
	return ans;
}
int main(){
	freopen ("celebration.in","r",stdin);
	freopen ("celebration.out","w",stdout);
	scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
	    for (int j=1;j<=m;j++)scanf("%d",&p[i][j]);
    }
    ll ans=solve()*m;
    if (ans>9000000)printf("No one knows.\n");
    else printf("%lld\n",ans);
	return 0;
}