B 比武招亲(上)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 998244353;
LL fac[maxn], inv[maxn];
LL mpow(LL a, LL x) {
if(x==0)return 1;
LL t = mpow(a, x>>1);
if(x%2==0)return t*t%mod;
return t*t%mod*a%mod;
}
LL init(){
fac[0]=inv[0]=1;
for(int i = 1; i < maxn; i++){
fac[i]=fac[i-1]*i%mod; inv[i]=mpow(fac[i],mod-2);
}return 0;
}
LL C(int x, int y) {
if(y<0 || y>x)return 0;
return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
init();
ios::sync_with_stdio(false);
LL n, m; cin>>n>>m;
LL ans = 0;
for(LL i = 1; i <= n; i++){
ans += C(i+m-2-1,m-2)*(i-1)%mod*(n-i+1)%mod;
}
cout<<ans%mod<<"\n";
return 0;
}
F 我的心是冰冰的
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
ios::sync_with_stdio(false);
int T; cin>>T;
while(T--){
int n; cin>>n;
if(n==1){cout<<"1\n"; continue;}
for(int i = 1; i < n; i++){
int x, y; cin>>x>>y;
}
cout<<2<<"\n";
}
return 0;
}