Submission #758671

# Submission time Handle Problem Language Result Execution time Memory
758671 2023-06-15T05:37:37 Z boris_mihov Simurgh (IOI17_simurgh) C++17
30 / 100
71 ms 4004 KB
#include "simurgh.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <set>

typedef long long llong;
const int MAXN = 500 + 10;
const int INF  = 1e9;

int n, m;
int timer;
int inComp[MAXN];
std::set <int> s;
std::vector <int> ans;
std::vector <int> spanning;
std::vector <std::pair <int,int>> edges;
std::vector <std::pair <int,int>> g[MAXN];

void dfs(int node)
{
    inComp[node] = timer;
    for (const auto &[i, idx] : g[node])
    {
        if (inComp[i] == 0)
        {
            spanning.push_back(idx);
            dfs(i);
        }
    }
}

std::vector <int> find_roads(int N, std::vector <int> u, std::vector <int> v)
{
	n = N;
    m = u.size();
    for (int i = 0 ; i < m ; ++i)
    {
        g[u[i] + 1].push_back({v[i] + 1, i});
        g[v[i] + 1].push_back({u[i] + 1, i});
    }

    int last = -1;
    int res = -1;

    for (int i = 1 ; i <= n ; ++i)
    {
        timer = 0;
        spanning.clear();
        std::fill(inComp + 1, inComp + 1 + n, 0);
        inComp[i] = -1;

        for (int j = 1 ; j <= n ; ++j)
        {
            if (inComp[j] != 0)
            {
                continue;
            }

            timer++;
            dfs(j);
        }

        std::sort(g[i].begin(), g[i].end(), [&](auto x, auto y)
        {
            return inComp[x.first] < inComp[y.first];
        });

        int curr = spanning.size();
        for (int j = 0 ; j < g[i].size() ; ++j)
        {
            if (j == 0 || inComp[g[i][j - 1].first] < inComp[g[i][j].first])
            {
                spanning.push_back(g[i][j].second);
            }
        }

        for (int j = 0 ; j <= g[i].size() ; ++j)
        {
            if (j == g[i].size() || (j > 0 && inComp[g[i][j - 1].first] < inComp[g[i][j].first]))
            {
                if (edges.size())
                {
                    std::sort(edges.begin(), edges.end(), [&](auto x, auto y)
                    {
                        return x.second < y.second;
                    });

                    ans.push_back(edges.back().first);
                    // std::cout << "in for: " << edges.back().first << ' ' << edges.back().second << '\n';
                    for (int k = (int)edges.size() - 2 ; k >= 0 ; --k)
                    {
                        if (edges[k].second != edges[k + 1].second)
                        {
                            // std::cout << "break: " << edges[k].second << ' ' << edges[k + 1].second << '\n';
                            break;
                        }

                        // std::cout << "in for: " << edges[k].first << ' ' << edges[k].second << ' ' << edges[k + 1].second << '\n';
                        ans.push_back(edges[k].first);
                    }
                }

                curr++;
                edges.clear();
                if (j == g[i].size())
                {
                    break;
                }
            }

            spanning[curr] = g[i][j].second;
            res = count_common_roads(spanning);
            // std::cout << "push: " << edges.size() << ' ' << g[i][j].second << ' ' << res << '\n';
            edges.push_back({g[i][j].second, res});
        }
    }

    for (const int &i : ans)
    {
        s.insert(i);
    }

    ans.clear();
    for (const int &i : s)
    {
        ans.push_back(i);
    }

    return ans;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:72:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int j = 0 ; j < g[i].size() ; ++j)
      |                          ~~^~~~~~~~~~~~~
simurgh.cpp:80:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for (int j = 0 ; j <= g[i].size() ; ++j)
      |                          ~~^~~~~~~~~~~~~~
simurgh.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             if (j == g[i].size() || (j > 0 && inComp[g[i][j - 1].first] < inComp[g[i][j].first]))
      |                 ~~^~~~~~~~~~~~~~
simurgh.cpp:108:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |                 if (j == g[i].size())
      |                     ~~^~~~~~~~~~~~~~
simurgh.cpp:45:9: warning: unused variable 'last' [-Wunused-variable]
   45 |     int last = -1;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 300 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 316 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 312 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 296 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 312 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 300 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 316 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 312 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 296 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 312 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 2 ms 340 KB correct
27 Correct 2 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 316 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 300 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 316 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 312 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 296 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 312 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 2 ms 340 KB correct
27 Correct 2 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 316 KB correct
34 Incorrect 71 ms 1540 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Incorrect 58 ms 4004 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 300 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 316 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 312 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 296 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 312 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 2 ms 340 KB correct
27 Correct 2 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 316 KB correct
34 Incorrect 71 ms 1540 KB WA in grader: NO
35 Halted 0 ms 0 KB -