QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661002#7671. Metal Processing PlantanthonyaaabcTL 1ms3828kbC++143.2kb2024-10-20 14:15:232024-10-20 14:15:24

Judging History

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

  • [2024-10-20 14:15:24]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3828kb
  • [2024-10-20 14:15:23]
  • 提交

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;
    }
    int cnt=0;
    for(int i=0;i<tp.size();i++)
    {
        int u=tp[i].u,v=tp[i].v;
        bool tg=0;
        if(find(u)==find(rev(v)))continue;
        else
        {
            fa[find(u)]=find(rev(v));
            fa[find(rev(v))]=find(u);
            if(find(u)==find(rev(u))||find(v)==find(rev(v)))
            {
                tg=1;
                
            }
        }
        cnt++;
        if(cnt>n)exit(114514);
        //cerr<<tp[i].c<<"??\n";
        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(tg)break;
    }
    if(check(0,0))
    {
        ans=min(ans,0);
    }
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

2
1

output:

0

result:

ok single line: '0'

Test #5:

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

input:

2
1000000000

output:

0

result:

ok single line: '0'

Test #6:

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

input:

3
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #7:

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

input:

4
1000000000 1000000000 1000000000
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #8:

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

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: