Submission #766848

# Submission time Handle Problem Language Result Execution time Memory
766848 2023-06-26T08:12:10 Z danikoynov Simurgh (IOI17_simurgh) C++14
0 / 100
13 ms 2848 KB
#include "simurgh.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 250;
struct disjoint_set_union
{
    int par[maxn];

    disjoint_set_union() {};

    disjoint_set_union(int n)
    {
        for (int i = 0; i < n; i ++)
            par[i] = i;
    }

    int find_leader(int v)
    {
        if (v == par[v])
            return v;
        return (par[v] = find_leader(par[v]));
    }

    bool is_connected(int v, int u)
    {
        return find_leader(v) == find_leader(u);
    }

    void unite(int v, int u)
    {
        v = find_leader(v);
        u = find_leader(u);
        if (v == u)
            return;
        par[v] = u;
    }
};
vector<int> find_roads(int n, vector<int> u, vector<int> v)
{
    vector < int > gold;
    int m = u.size(), queries = 0;
    for (int t = 0; t < n - 1; t ++)
    {
        disjoint_set_union dsu(n);
        int cp = n;
        vector < int > res;
        for (int edge : gold)
        {
            dsu.unite(u[edge], v[edge]);
            cp --;
            res.push_back(edge);
        }
        for (int j = 0; j < m && cp > 2; j ++)
        {
            if (!dsu.is_connected(u[j], v[j]))
            {
                dsu.unite(u[j], v[j]);
                cp --;
                res.push_back(j);
            }
        }
        vector < int> pot;
        for (int i = 0; i < m; i ++)
        {
            if (!dsu.is_connected(u[i], v[i]))
                pot.push_back(i);
        }


        if (pot.size() == 1)
        {
            gold.push_back(pot[0]);
        }
        else
        {
            res.push_back(pot[0]);
            int v1 = count_common_roads(res);
            res.pop_back();
            res.push_back(pot[1]);
            int v2 = count_common_roads(res);
            res.pop_back();
            if (v1 > v2)
            {
                gold.push_back(pot[0]);
            }
            else if (v1 < v2)
            {
                gold.push_back(pot[1]);
            }
            else
            {
                for (int i = 2; i < pot.size(); i ++)
                {
                    res.push_back(pot[i]);
                    if (count_common_roads(res) != v1)
                    {
                        gold.push_back(pot[i]);
                        break;
                    }
                    res.pop_back();
                }
            }
        }

    }
    return gold;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:94:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |                 for (int i = 2; i < pot.size(); i ++)
      |                                 ~~^~~~~~~~~~~~
simurgh.cpp:43:23: warning: unused variable 'queries' [-Wunused-variable]
   43 |     int m = u.size(), queries = 0;
      |                       ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Runtime error 13 ms 2848 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB WA in grader: NO
2 Halted 0 ms 0 KB -