QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660948#7671. Metal Processing PlantanthonyaaabcTL 0ms3832kbC++143.5kb2024-10-20 14:01:462024-10-20 14:01:47

Judging History

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

  • [2024-10-20 14:01:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3832kb
  • [2024-10-20 14:01:46]
  • 提交

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;
int clc(vector<int>&a,vector<int>&b)
{
    int mxa=0,mxb=0;
    for(int i=0;i<a.size();i++)
    {
        for(int j=0;j<a.size();j++)
        {
            mxa=max(mxa,mp[a[i]][a[j]]);
        }
    }
    for(int i=0;i<b.size();i++)
    {
        for(int j=0;j<b.size();j++)
        {
            mxb=max(mxb,mp[b[i]][b[j]]);
        }
    }
    return mxa+mxb;
}
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(low,0,sizeof(low));
    memset(co,0,sizeof(co));
    memset(fir,0,sizeof(fir));
    memset(in,0,sizeof(in));
    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;
    for(int i=1;i<=n;i++)
    {
        vector<int>a,b;
        a.push_back(i);
        for(int j=1;j<=n;j++)
        {
            if(i==j)continue;
            b.push_back(j);
        }
        ans=min(ans,clc(a,b));
    }
    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;
        }
    }
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

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: 3624kb

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: 3568kb

input:

1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

2
1

output:

0

result:

ok single line: '0'

Test #5:

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

input:

2
1000000000

output:

0

result:

ok single line: '0'

Test #6:

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

input:

3
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #7:

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

input:

4
1000000000 1000000000 1000000000
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #8:

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

input:

3
78 97
24

output:

24

result:

ok single line: '24'

Test #9:

score: -100
Time Limit Exceeded

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:


result: