Submission #758689

# Submission time Handle Problem Language Result Execution time Memory
758689 2023-06-15T06:18:30 Z boris_mihov Simurgh (IOI17_simurgh) C++17
30 / 100
72 ms 7276 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 MAXM = 30000;
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];
bool isGood[MAXM];

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);
        bool didntPush = true;
        inComp[i] = -1;

        for (const int &j : ans)
        {
            isGood[j] = true;
        }

        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]))
            {
                assert (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;
                }
            }

            // if (i < g[i][j].first)
            // {
                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});
            // } else if (didntPush && isGood[g[i][j].second])
            // {
            //     didntPush = false;
            //     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: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:88: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]
   88 |         for (int j = 0 ; j <= g[i].size() ; ++j)
      |                          ~~^~~~~~~~~~~~~~
simurgh.cpp:90: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]
   90 |             if (j == g[i].size() || (j > 0 && inComp[g[i][j - 1].first] < inComp[g[i][j].first]))
      |                 ~~^~~~~~~~~~~~~~
simurgh.cpp:114: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]
  114 |                 if (j == g[i].size())
      |                     ~~^~~~~~~~~~~~~~
simurgh.cpp:55:14: warning: unused variable 'didntPush' [-Wunused-variable]
   55 |         bool didntPush = true;
      |              ^~~~~~~~~
simurgh.cpp:47:9: warning: unused variable 'last' [-Wunused-variable]
   47 |     int last = -1;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 320 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 320 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 316 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 320 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 320 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 316 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 3 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 1 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 1 ms 340 KB correct
27 Correct 2 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 316 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 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 1 ms 320 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 320 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 316 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 3 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 1 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 1 ms 340 KB correct
27 Correct 2 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 316 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 72 ms 1484 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 320 KB correct
3 Runtime error 20 ms 7276 KB Execution killed with signal 11
4 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 Correct 1 ms 212 KB correct
4 Correct 1 ms 320 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 320 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 1 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 316 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 3 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 1 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 1 ms 340 KB correct
27 Correct 2 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 316 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 72 ms 1484 KB WA in grader: NO
35 Halted 0 ms 0 KB -