QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#507358#7671. Metal Processing PlantZpairWA 17ms5132kbC++202.6kb2024-08-06 16:44:482024-08-06 16:44:48

Judging History

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

  • [2024-08-06 16:44:48]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:5132kb
  • [2024-08-06 16:44:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=205;
int d[N][N],n;
struct node{
	int x,y,v;
	bool operator <(const node &ret)const{
		return v>ret.v;
	}
}t[N*N];
int m;
int f[N];
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
vector<int> e[N];
int dep[N],fa[N],lca[N][N];
void dfs(int p){
	dep[p]=dep[fa[p]]+1;
	for(int t:e[p]){
		if(t==fa[p])continue;
		fa[t]=p,dfs(t);
	}
}
int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	while(dep[x]!=dep[y])x=fa[x];
	while(x!=y)x=fa[x],y=fa[y];
	return x;
}
int dis(int x,int y){
	return dep[x]+dep[y]-2*dep[lca[x][y]];
}
namespace ck{
	const int M=N+N;
	vector<int> e[M],g[M];
	void add(int x,int y){
		e[x].push_back(y);
		g[y].push_back(x);
	}
	bool vis[M];
	int q[M],tp;
	int bel[M],tot;
	void dfs1(int p){
		vis[p]=1;
		for(int t:e[p])
			if(!vis[t])
				dfs1(t);
		q[++tp]=p;
	}
	void dfs2(int p){
		bel[p]=tot;
		for(int t:g[p])
			if(!bel[t])
				dfs2(t);
	}
	bool check(){
		for(int i=1;i<=n+n;++i)
			if(!vis[i])dfs1(i);
		for(int i=n+n;i>=1;--i)
			if(!bel[q[i]])++tot,dfs2(q[i]);
		bool pd=1;
		for(int i=1;i<=n;++i)
			if(bel[i]==bel[i+n])
				pd=0;
		tp=tot=0;
		for(int i=1;i<=n+n;++i){
			e[i].clear();
			g[i].clear();
		}
		memset(vis,0,sizeof(vis));
		memset(q,0,sizeof(q));
		memset(bel,0,sizeof(bel));
		return pd;
	}
}
using ck::add;
using ck::check;
bool check(int dA,int dB){
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j){
			if(d[i][j]>dA){
				add(i,j+n);
				add(i+n,j);
				add(j,i+n);
				add(j+n,i);
			}
			else if(d[i][j]>dB){
				add(i+n,j);
				add(j+n,i);
			}
		}
	return check();
}
int mn=2e9+1;
void calc(int dA){
	int l=0,r=dA,mid=(l+r)>>1,ans=-1;
	while(l<=r){
		if(check(dA,mid))
			ans=mid,r=mid-1;
		else l=mid+1;
		mid=(l+r)>>1;
	}
	if(ans!=-1)
		mn=min(mn,dA+ans);
}//dA
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			scanf("%d",&d[i][j]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<i;++j)
			d[i][j]=d[j][i];
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			t[++m]={i,j,d[i][j]};
	sort(t+1,t+m+1);
	for(int i=1;i<=n;++i)f[i]=i;
	for(int i=1;i<=m;++i){
		int x=t[i].x,y=t[i].y;
		int fx=find(x),fy=find(y);
		if(fx!=fy){
			e[x].push_back(y);
			f[fx]=fy;
		}
	}
	dfs(1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			lca[i][j]=LCA(i,j);
	for(int i=1;i<=n;++i)f[i]=i;
	for(int i=1;i<=m;++i){
		int x=t[i].x,y=t[i].y,v=t[i].v;
		int fx=find(x),fy=find(y);
		if(fx!=fy)calc(v),f[fx]=fy;
		else if((dis(x,y)+1)&1){
			calc(v);
			break;
		}
	}
	calc(0);
	cout<<mn;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3796kb

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: 0
Accepted
time: 0ms
memory: 3652kb

input:

1

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2
1

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

2
1000000000

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

3
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

4
1000000000 1000000000 1000000000
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

3
78 97
24

output:

24

result:

ok single line: '24'

Test #9:

score: -100
Wrong Answer
time: 17ms
memory: 5132kb

input:

200
202018752 202018795 202018793 100018905 202018758 202018741 202018727 202018766 202018728 100018879 202018781 100018860 202018785 100018841 100018910 100018836 100018883 100018847 202018734 202018775 100018830 100018901 202018773 202018754 202018737 100018843 202018788 202018778 202018777 202018...

output:

202019602

result:

wrong answer 1st lines differ - expected: '201024848', found: '202019602'