QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797174#7671. Metal Processing PlantcrsfaaWA 1ms7692kbC++141.8kb2024-12-02 18:07:342024-12-02 18:07:34

Judging History

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

  • [2024-12-02 18:07:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7692kb
  • [2024-12-02 18:07:34]
  • 提交

answer

#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?-1:1,ch=getchar();
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
/*
>mx:双向
>mn:单向 
*/
const int mxn=1e5+5;
struct edge
{
	int x,y,v;
	friend bool operator <(const edge &x,const edge &y)
	{
		return x.v<y.v;
	}
}e[mxn];
int f[mxn];
int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}
int n,m;
vector<int> a[mxn];
int dfn[mxn],low[mxn],col[mxn],dcnt,ccnt;
bool vis[mxn];
stack<int> stk;
void dfs(int d)
{
	stk.push(d),vis[d]=1;
	dfn[d]=low[d]=++dcnt;
	for(auto x:a[d])
		if(!dfn[x])
		{
			dfs(x);
			low[d]=min(low[d],low[x]);
		}
		else if(vis[x])
			low[d]=min(low[d],dfn[x]);
	if(dfn[d]==low[d])
	{
		ccnt++;
		int p;
		do
		{
			p=stk.top();
			stk.pop(),vis[p]=0;
			col[p]=ccnt;
		}while(p!=d);
	}
}
bool check(int l,int r)
{
	int i,j;
	for(i=1;i<=n*2;i++)
		a[i].clear();
	for(i=l+1;i<=r;i++)
		a[find(e[i].x)].push_back(find(e[i].y+n)),
		a[find(e[i].y)].push_back(find(e[i].x+n));
	memset(dfn,0,n*2+1<<2);
	for(i=1;i<=n*2;i++)
		if(!dfn[i])
			dfs(i);
	for(i=1;i<=n;i++)
		if(col[find(i)]==col[find(i+n)])
			return 0;
	return 1;
}
int main()
{
	n=read();
	int i,j;
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			e[++m].x=i,e[m].y=j,e[m].v=read();
	sort(e+1,e+1+m);
	for(i=1;i<=n*2;i++)
		f[i]=i;
	int ans=2e9;
	for(i=m;i;i--)
		if(find(e[i].x)!=find(e[i].y+n)||find(e[i].x+n)!=find(e[i].y))
		{
			int w=i;
			for(j=1<<__lg(i);j;j>>=1)
				w-=(w-j>=1&&check(w-j,i))*j;
			if(w<i)
				ans=min(ans,e[i].v+e[w].v);
			f[find(e[i].x)]=find(e[i].y+n);
			f[find(e[i].x+n)]=find(e[i].y);
		}
	cout<<ans;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6264kb

input:

5
4 5 0 2
1 3 7
2 0
4

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7560kb

input:

7
1 10 5 5 5 5
5 10 5 5 5
100 100 5 5
10 5 5
98 99
3

output:

15

result:

ok single line: '15'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7692kb

input:

1

output:

2000000000

result:

wrong answer 1st lines differ - expected: '0', found: '2000000000'