QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660967 | #7671. Metal Processing Plant | anthonyaaabc | WA | 0ms | 3832kb | C++14 | 2.9kb | 2024-10-20 14:05:53 | 2024-10-20 14:05:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=405;
int n;
int mp[N][N];
vector<int>aa,bb;
int ans=0;
struct edge
{
int u,v,c;
};
bool cmp(edge a,edge b)
{
return a.c>b.c;
}
int fa[N];
int fir[N],nex[4*N],to[4*N];
int dfn[N],low[N],tot,col,co[N];
bool in[N];
list<int>s;
inline int rev(int x)
{
if(x>n)return x-n;
else return x+n;
}
int cnt=1;
void dfs(int u)
{
dfn[u]=low[u]=++tot;
in[u]=1;
s.push_back(u);
for(int i=fir[u];i;i=nex[i])
{
int v=to[i];
if(!dfn[v])
{
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(in[v])
{
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u])
{
co[u]=++col;
in[u]=0;
while(s.back()!=u)
{
co[s.back()]=col;
in[s.back()]=0;
s.pop_back();
}
s.pop_back();
}
}
void insert(int u,int v)
{
nex[++cnt]=fir[u];
fir[u]=cnt;
to[cnt]=v;
}
int find(int x)
{
if(fa[x]==x)return x;
return fa[x]=find(fa[x]);
}
bool check(int a,int b)
{
memset(dfn,0,sizeof(dfn));
memset(fir,0,sizeof(fir));
cnt=0;
tot=0;
col=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(mp[i][j]>a)
{
insert(i,rev(j));
insert(j,rev(i));
}
if(mp[i][j]>b)
{
insert(rev(i),j);
insert(rev(j),i);
}
}
}
s.clear();
for(int i=1;i<=2*n;i++)
{
if(dfn[i]==0)
{
dfs(i);
}
}
for(int i=1;i<=2*n;i++)
{
if(co[i]==co[rev(i)])
{
return 0;
}
}
return 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
int mx=0;
vector<edge>tp;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
cin>>mp[i][j];
tp.push_back({i,j,mp[i][j]});
mp[j][i]=mp[i][j];
mx=max(mx,mp[i][j]);
}
}
int ans=2e9+7;
sort(tp.begin(),tp.end(),cmp);
for(int i=1;i<=2*n;i++)
{
fa[i]=i;
}
for(int i=0;i<tp.size();i++)
{
int u=tp[i].u,v=tp[i].v;
if(find(u)==find(v))continue;
else
{
fa[find(u)]=find(v);
}
int l=0,r=tp[i].c;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(tp[i].c,mid))
{
ans=min(ans,mid+tp[i].c);
r=mid-1;
}
else l=mid+1;
}
}
if(check(0,0))
{
ans=min(ans,0);
}
cout<<ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
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: 3488kb
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: 3528kb
input:
1
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
2 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
2 1000000000
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
3 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
4 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1000000000
result:
ok single line: '1000000000'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3472kb
input:
3 78 97 24
output:
78
result:
wrong answer 1st lines differ - expected: '24', found: '78'