传送门
解析:
参考论文:https://www.sciencedirect.com/science/article/pii/0095895679900455?via%3Dihub
关于竞赛图的一个性质: L a n d a u T h e o r e m Landau Theorem LandauTheorem :竞赛图出度序列 { s i } \{s_i\} {si} 合法当且仅当,对于任意子集 X X X ,都有 ∑ i ∈ X s i ≥ ( ∣ X ∣ 2 ) \sum_{i\in X}s_i\geq {|X|\choose 2} ∑i∈Xsi≥(2∣X∣),且 s i s_i si 总和为 ( ∣ S ∣ 2 ) |S|\choose 2 (2∣S∣)。
必要性:显然任意子集内部构成一个竞赛图,加上外部点连进来的,总度数不能小于内部边数。
充分性的证明稍微麻烦一点。
考虑通过得分序列构造出竞赛图。
将得分序列排序,显然不影响图的存在性。然后从小到大处理,对于 s i s_i si 需要有 n − s i − 1 n-s_i-1 n−si−1 个点连向它,直接选剩余序列中 s s s最大的那些点就行了,接下来直接处理后面的剩余序列即可。
不难发现整个过程剩余序列都是得分序列。
一个高效一点的构造方法见:here
一个不用构造直接用Hall定理证明的方法见:here
代码:
#include<bits/stdc++.h>
#define ll long long
#define re register
namespace IO{
inline char gc(){
static const int Rlen=1<<22|1;static char buf[Rlen],*p1,*p2;
return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++;
}template<typename T>T get_integer(){
bool f=false;char c;while(!isdigit(c=gc()))f=c=='-';T x=c^48;
while(isdigit(c=gc()))x=((x+(x<<2))<<1)+(c^48);return f?-x:x;
}inline int gi(){return get_integer<int>();}
inline ll gl(){return get_integer<ll>();}
}
using IO::gi;
inline ll C(ll a){
return a*(a-1)>>1;
}
int a[50007];
void work(){
int n=gi();bool f=true;
for(int i=1;i<=n;++i)a[i]=gi();
std::sort(a+1,a+n+1);ll s=0;
for(int re i=1;i<=n&&f;++i)
f=(s+=a[i])>=C(i);
f=f&&(s==C(n));
puts(f?"It seems to have no problem.":"The data have been tampered with!");
}
void Main(){
for(int T=gi();T--;)work();
}
inline void file(){
#ifdef zxyoi
freopen("in","r",stdin);
#endif
}signed main(){file();Main();return 0;}