QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788915#9623. 合成大西瓜Lonelyper#WA 1ms3568kbC++174.2kb2024-11-27 18:44:292024-11-27 18:44:29

Judging History

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

  • [2024-11-27 18:44:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3568kb
  • [2024-11-27 18:44:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
void print(vector<int> nums)
{
    for(int x:nums)
    cout<<x<<" ";
    cout<<endl;
}
static int cal3(vector<int> nums)
{
    return max(nums[0],min(nums[1],nums[2]));
}
class meth
{
    public:
    int n;
    vector<vector<int>> edges;
    //vector<int> leaf;
    vector<int> lock;
    vector<int> mark;
    vector<int> status;
    vector<int> nums;
    meth(int sz,vector<vector<int>> raw_edges,vector<int> o_nums):edges(sz),mark(sz,0),status(sz,0),lock(sz,0)
    {
        n=sz;
        nums=o_nums;
        for(auto arr:raw_edges)
        {
        edges[arr[0]].push_back(arr[1]);
        edges[arr[1]].push_back(arr[0]);
        ++lock[arr[0]];
        ++lock[arr[1]];
        }
    }
    void make_status()
    {
        for(int i=0;i<n;++i)
        {
            for(int x:edges[i])
            if(lock[x]==1)
            ++status[i];
        }
    }
    void cutDouble()
    {
        make_status();
        queue<int> qu;//存储根
        for(int i=0;i<n;++i)//根
        {
            if(status[i]==2)
            qu.push(i);
        }
        while(!qu.empty())
        {
            int root=qu.front();//cout<<root<<endl;
            qu.pop();
            vector<int> cache;
            cache.push_back(nums[root]);
            for(int x:edges[root])
            {
                if(mark[x])
                continue;
                if(lock[x]==1)
                {
                    --lock[x];
                    mark[x]=1;
                    cache.push_back(nums[x]);
                }
            }
            nums[root]=cal3(cache);
            lock[root]-=2;
            if(lock[root]==1)
            {
                for(int x:edges[root])
                {
                    if(mark[x])
                    continue;
                    ++status[x];
                    if(status[x]==2)
                    qu.push(x);
                }
            }
        }

    }

    int cal()
    {
        int mark_cnt=0;
        for(int x:mark)
        mark_cnt+=x;
        if(mark_cnt==n-1)
        {
            for(int i=0;i<n;++i)
            if(mark[i]==0)
            return nums[i];
        }
        int maxv=0;
        for(int i=0;i<n;++i)
        {
            if(mark[i])
            continue;
            if(status[i]==2)//一次操作中的根
            continue;
            if(lock[i]==1)
            continue;
            int target=-1;
            for(int x:edges[i])
            {
                if(mark[x])
                continue;
                if(lock[x]==1)
                {
                    target=x;
                    break;
                }
            }
            if(target!=-1)
            continue;
            vector<int> temp;
            if(target!=-1)
            {
                for(int x:edges[i])
                {
                    if(mark[x])
                    continue;
                    if(lock[x]==1)
                    continue;
                    temp.push_back(nums[x]);
                }
                sort(temp.rbegin(),temp.rend());
                int rst=max(nums[i],min(nums[target],temp[0]));
                maxv=max(maxv,rst);
            }
            else
            {
                for(int x:edges[i])
                {
                    if(mark[x])
                    continue;
                    temp.push_back(nums[x]);
                }
                sort(temp.rbegin(),temp.rend());
                int rst=max(nums[i],min(temp[0],temp[1]));
                maxv=max(maxv,rst);
            }
        }
        //print(nums);
        return maxv;
    }

};
void Lonelyper(){
    int n,m;
    cin>>n>>m;
    vector<int> weight(n);
    for(auto&x:weight)
    cin>>x;
    vector<vector<int>> raw_edges(m,vector<int>(2));    
    for(auto&arr:raw_edges)
    {
    cin>>arr[0]>>arr[1];
    --arr[0];
    --arr[1];
    }
    meth *test=new meth(n,raw_edges,weight);
    test->cutDouble();
    int ans=test->cal();
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t --) Lonelyper();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3568kb

input:

7 9
1 4 1 3 3 6 7
5 4
3 6
3 4
2 3
5 2
2 6
6 7
5 1
4 6

output:

4

result:

wrong answer 1st lines differ - expected: '6', found: '4'