江苏省常州建设高等职业技术学校网站,企信网企业信息查询平台官网,国内知名建筑设计公司,如何编辑网站模板传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a; 思路#xff1a;
对于每个数的位置(i,j)(i,j)(i,j)#xff0c;如果将这个位置染黑#xff0c;那么我们连一个i−jni-jni−jn的边#xff0c;可以发现我们的操作不影响连通性。如果想要全部染…传送门
文章目录题意思路题意 思路
对于每个数的位置(i,j)(i,j)(i,j)如果将这个位置染黑那么我们连一个i−jni-jni−jn的边可以发现我们的操作不影响连通性。如果想要全部染黑等价于将其变成联通图。 所以跑一遍最小生成树即可用克鲁斯卡尔的话需要桶排。
// Problem: Black and white
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11254/B
// Memory Limit: 1048576 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#includerandom
#includecassert
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].ltr[u].r)1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N5050,INF0x3f3f3f3f;
const double eps1e-6;int a,b,c,d,mod;
int n,m;
int p[N*20];
vectorPIIv[N*20];
LL cre[N*N];int find(int x) {return xp[x]? x:p[x]find(p[x]);
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);cinnmabcdmod;cre[0]a;for(int i1;in*m;i) {cre[i](cre[i-1]*cre[i-1]%mod*b%modcre[i-1]*c%modd)%mod;v[cre[i]].pb({(i-1)/m,(i-1)%m});}LL ans0;for(int i0;inm100;i) p[i]i;for(int i0;imod;i) {for(auto x:v[i]) {int pafind(x.X),pbfind(x.Yn);if(papb) continue;ansi; p[pa]pb;}}coutansendl;return 0;
}
/**/