QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#330#103696#6402. MEXimum Spanning TreeCrysflyCrysflyFailed.2023-05-07 08:25:002023-05-07 08:25:00

詳細信息

Extra Test:

Invalid Input

input:

40000 79999
1 2 0
2 3 0
3 4 0
4 5 0
5 6 0
6 7 0
7 8 0
8 9 0
9 10 0
10 11 0
11 12 0
12 13 0
13 14 0
14 15 0
15 16 0
16 17 0
17 18 0
18 19 0
19 20 0
20 21 0
21 22 0
22 23 0
23 24 0
24 25 0
25 26 0
26 27 0
27 28 0
28 29 0
29 30 0
30 31 0
31 32 0
32 33 0
33 34 0
34 35 0
35 36 0
36 37 0
37 38 0
38 39 0
3...

output:


result:

FAIL Integer parameter [name=n] equals to 40000, violates the range [1, 1000] (stdin, line 1)

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103696#6402. MEXimum Spanning TreeCrysflyWA 14ms3616kbC++172.9kb2023-05-07 08:20:102023-05-07 08:26:03

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 1005
#define inf 0x3f3f3f3f

int n,m;
vector<pii>e[maxn];

struct DSU{
	int fa[maxn],cnt;
	int gf(int x){
		while(x^fa[x])x=fa[x]=fa[fa[x]];
		return x;
	}
	void init(){
		For(i,1,n)fa[i]=i;
		cnt=n; 
	}
	int merge(int u,int v){
		u=gf(u),v=gf(v);
		if(u!=v)return fa[u]=v,--cnt,1;
		else return 0;
	}
}D,tmp;

int per[maxn];
mt19937_64 rnd(time(0));

bool chk(int k)
{
	if(!e[k].size())return 0;
	For(i,0,k)per[i]=i;
//	sort(per,per+k+1,[&](int x,int y){
//		return e[x].size()<e[y].size();
//	});
	shuffle(per,per+k+1,rnd);
	int cnt=0;
	tmp.init();
	For(ii,0,k){
		int i=per[ii];
		for(auto it:e[i]){
			int u=it.fi,v=it.se;
			cnt+=tmp.merge(u,v);
		}
		if(cnt<ii+1){
			return 0;
		}
	}
	
	return 1;
}

signed main()
{
	n=read(),m=read();
	For(i,1,m){
		int u=read(),v=read(),w=read();
		e[w].pb(mkp(u,v));
	}
	For(i,0,n){
		if(!chk(i)){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}