Submission #1100018

# Submission time Handle Problem Language Result Execution time Memory
1100018 2024-10-12T11:46:00 Z MMihalev Simurgh (IOI17_simurgh) C++14
0 / 100
0 ms 348 KB
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
#include "simurgh.h"
using namespace std;
const int MAX_N=5e2+2;
const int MAX_M=125000;
int n,m;
vector<pair<int,int>>g[MAX_N];
vector<int>edges;
bool used[MAX_N];

bool stat[MAX_M];

void reset()
{
    edges.clear();
    for(int i=0;i<n;i++)
    {
        used[i]=0;
    }
}
void dfs(int u)
{
    used[u]=1;
    for(auto [v,edge]:g[u])
    {
        if(used[v])continue;
        edges.push_back(edge);
        dfs(v);
    }
}
vector<int> find_roads(int N, vector<int> u, vector<int> v)
{
    n=N;
    m=u.size();
    vector<int>ans;
    for(int i=0;i<m;i++)
    {
        g[u[i]].push_back({v[i],i});
        g[v[i]].push_back({u[i],i});
    }

    for(int u=0;u<n;u++)
    {
        vector<int>marked;
        bool changed=0;
        for(auto [v,edge]:g[u])
        {
            if(v<u)continue;
            reset();
            used[u]=1;
            dfs(v);
            edges.push_back(edge);
            marked.push_back(edge);
            break;
        }
        int ma=count_common_roads(edges);

        for(auto [v,edge]:g[u])
        {
            if(v<u)continue;
            if(edges.back()==edge)continue;

            edges.pop_back();
            edges.push_back(edge);
            int cur=count_common_roads(edges);
            if(cur>ma)
            {
                marked.clear();
                changed=1;
                marked.push_back(edge);
            }
            else if(cur==ma)
            {
                marked.push_back(edge);
            }
        }

        if(changed)
        {
            for(int edge:marked)stat[edge]=1;
        }
        else
        {
            int forsure=-1;
            for(auto [v,edge]:g[u])
            {
                if(stat[edge])forsure=edge;
            }

            if(forsure==-1)
            {
                for(int edge:marked)stat[edge]=1;
            }
            else
            {
                edges.pop_back();
                edges.push_back(forsure);
                int forsuremax=count_common_roads(edges);

                if(forsuremax==ma)for(int edge:marked)stat[edge]=1;
            }
        }
    }

    for(int i=0;i<m;i++)
    {
        if(stat[i])ans.push_back(i);
    }

    return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |     for(auto [v,edge]:g[u])
      |              ^
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:49:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |         for(auto [v,edge]:g[u])
      |                  ^
simurgh.cpp:61:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         for(auto [v,edge]:g[u])
      |                  ^
simurgh.cpp:88:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   88 |             for(auto [v,edge]:g[u])
      |                      ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -