QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741755#9623. 合成大西瓜ATM12345#WA 4ms32460kbC++171.7kb2024-11-13 15:10:072024-11-13 15:10:07

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 15:10:07]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:32460kb
  • [2024-11-13 15:10:07]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define LL long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
#define all(x) x.begin(),x.end()
#define inf 1e18

using namespace std;
ll n,m,k;
ll a[Ma];
ll fa[Ma],siz[Ma];
ll vis[Ma];

vector <ll> v[Ma];


struct node{
	ll num,w;
	bool operator <(const node &A)const{
		return w>A.w;
	}
}t[Ma];

ll find(ll x)
{
	if (x==fa[x]) return fa[x];
	return fa[x]=find(fa[x]);
}


void merage(ll x,ll y)
{
	x=find(x),y=find(y);
	if (x==y)
		return;
	siz[x]+=siz[y];
	if (v[x].size()<v[y].size())
		swap(v[x],v[y]);
	for (auto z:v[y])
		if (x!=find(z))
			v[x].pb(find(z));
	fa[y]=x;
	return;
}

bool ok(ll x)
{
	x=find(x);
	ll res=0;
	if (!vis[x])
		res+=siz[x],vis[x]=1;
	for (auto z:v[x])
	{
		ll y=find(z);
		if (!vis[y])
			res+=siz[y],vis[y]=1;
	}
	if (res==n)
		return 1;
	vis[x]=0;
	for (auto z:v[x])
	{
		ll y=find(z);
		vis[y]=0;
	}
	for (auto z:v[x])
	{
		merage(x,z);
	}
	return 0;
}

void sol()
{
	cin>>n>>m;
	for (ll i=1;i<=n;i++)
		fa[i]=i,siz[i]=1;
	for (ll i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		t[i]={i,x};	
	}
	for (ll i=1;i<=m;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[x].pb(y),v[y].pb(x);
	}
	sort(t+1,t+n+1);
	for (ll i=1;i<=n;i++)
	{
		if (ok(t[i].num))
		{
			printf("%lld\n",t[i].num);
			return;
		}
	}
	return;
}

int main()
{
	IOS
	ll tt=1;
	//cin>>tt;
	while (tt--)
		sol();
	return 0;
}

/*
7 7
1 1 2 3 1 2 1
1 2
2 3
1 3
2 4
2 5
5 6
5 7

*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 32460kb

input:

7 9
1 4 1 3 3 6 7
5 4
3 6
3 4
2 3
5 2
2 6
6 7
5 1
4 6

output:

4

result:

wrong answer 1st lines differ - expected: '6', found: '4'