跳到正文

题解

题解:P11862 「o.OI R1」Easy ver.

末然Ender约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年3月10日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 2 分钟
获赞
2
题目
P11862

版本

  1. v1当前

题解:P11862 「o.OI R1」Easy ver.

思路

显而易见,每一个节点最少都要有一条边链接,而这条边的边权不会小于这个点的编号,也就是说除了最小的 11 每个数都至少对应有一条边边权不小于该点编号,想要让最小生成树的边权和最小,只需要保证每个点(11 除外)都相邻一个比他编号小的数即可,所以我们直接从 11 输出到 n⋅mn\cdot m 即可满足要求。

代码

C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
void read(T& x){x=0;char ch=getchar();long long f=1;while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}x*=f;}
template<typename T,typename... Args>
void read(T& first,Args&... args){read(first);read(args...);}
template<typename T>
void write(T arg){T x=arg;if (x<0){putchar('-');x=-x;}if(x>9){write(x/10);}putchar(x%10+'0');}
template<typename T,typename... Args>
void write(T arg,Args... args){write(arg);if(sizeof...(args) !=0){putchar(' ');write(args...);}}
const ll N=1e5+4;
int main(){
	ll n,m;
	read(n,m);
	for(int i=0;i<n;i++){
		for(int j=1;j<=m;j++){
			write(i*m+j);putchar(' ');
		}
		putchar('\n');
	}
	return 0;
}
原文