Submission #290406

# Submission time Handle Problem Language Result Execution time Memory
290406 2020-09-03T18:05:16 Z A02 Simurgh (IOI17_simurgh) C++14
51 / 100
225 ms 3712 KB
#include <bits/stdc++.h>
#include "simurgh.h"

using namespace std;

vector<int> find_roads(int n, vector<int> u, vector<int> v) {

	vector<vector<pair<int, int> > > adjacent (n, vector<pair<int, int> >());

	for (int i = 0; i < u.size(); i++){
        adjacent[u[i]].push_back(make_pair(v[i], i));
        adjacent[v[i]].push_back(make_pair(u[i], i));
	}

	int m = u.size();

	vector<int> decided (m, -1);

	for (int i = 0; i < n; i++){

        vector<int> established_tree;

        vector<int> region (n, -1);
        region[i] = -2;
        int c_region = 0;

        for (int a = 0; a < n; a++){

            if (a != i){
                if (region[a] == -1){

                    region[a] = c_region;

                    queue<int> to_visit;
                    to_visit.push(a);

                    while (!to_visit.empty()){

                        int current = to_visit.front();
                        to_visit.pop();

                        for (int j = 0; j < adjacent[current].size(); j++){
                            int next = adjacent[current][j].first;
                            if (region[next] == -1){
                                established_tree.push_back(adjacent[current][j].second);
                                to_visit.push(next);
                                region[next] = c_region;
                            }
                        }

                    }

                    c_region++;
                }
            }
        }


        vector<vector<int> > possible_additional_edges (c_region, vector<int>());

        vector<int> reference_set (c_region, -1);
        vector<int> reference_value (c_region, -1);

        for (int j = 0; j < adjacent[i].size(); j++){
            int adjacent_vertex = adjacent[i][j].first;
            int edge_label = adjacent[i][j].second;
            int v_region = region[adjacent_vertex];

            possible_additional_edges[v_region].push_back(edge_label);

            if (decided[edge_label] != -1 && reference_set[v_region] == -1){
                reference_set[v_region] = edge_label;
                reference_value[v_region] = decided[edge_label];
            }
        }

        for (int r = 0; r < c_region; r++){
            if (reference_set[r] == -1){
                reference_set[r] = possible_additional_edges[r][0];
            }
        }

        vector<int> full_reference_set = established_tree;
        for (int j = 0; j < c_region; j++){
            full_reference_set.push_back(reference_set[j]);
        }

        int reference_total = count_common_roads(full_reference_set);

        for (int r = 0; r < c_region; r++){
            int current_reference_value = reference_value[r];
            vector<int> current_set = full_reference_set;
            current_set.erase(find(current_set.begin(), current_set.end(), reference_set[r]));

            if (current_reference_value != -1){
                for (int j = 0; j < possible_additional_edges[r].size(); j++){
                    int current_edge = possible_additional_edges[r][j];
                    if (decided[current_edge] == -1){
                        current_set.push_back(current_edge);
                        int new_total = count_common_roads(current_set);
                        current_set.pop_back();

                        if (new_total == reference_total){
                            decided[current_edge] = current_reference_value;
                        } else {
                            if (current_reference_value == 0){
                                decided[current_edge] = 1;
                            } else{
                                decided[current_edge] = 0;
                            }
                        }
                    }
                }
            } else {
                vector<int> values_region_r (possible_additional_edges[r].size(), 0);

                if (possible_additional_edges[r].size() == 1){
                    decided[possible_additional_edges[r][0]] = 1;
                } else{

                    for (int j = 0; j < possible_additional_edges[r].size(); j++){
                        current_set.push_back(possible_additional_edges[r][j]);
                        values_region_r[j] = count_common_roads(current_set);
                        current_set.pop_back();
                    }

                    int upper = *max_element(values_region_r.begin(), values_region_r.end());

                    for (int j = 0; j < possible_additional_edges[r].size(); j++){
                        if (values_region_r[j] == upper){
                            decided[possible_additional_edges[r][j]] = 1;
                        } else {
                            decided[possible_additional_edges[r][j]] = 0;
                        }
                    }
                }
            }

        }
	}

    vector<int> answer;
    for (int i = 0; i < decided.size(); i++){
        if (decided[i] == 1){
            answer.push_back(i);
        }
    }

	return answer;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < u.size(); i++){
      |                  ~~^~~~~~~~~~
simurgh.cpp:42:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |                         for (int j = 0; j < adjacent[current].size(); j++){
      |                                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for (int j = 0; j < adjacent[i].size(); j++){
      |                         ~~^~~~~~~~~~~~~~~~~~~~
simurgh.cpp:96:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |                 for (int j = 0; j < possible_additional_edges[r].size(); j++){
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:121:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |                     for (int j = 0; j < possible_additional_edges[r].size(); j++){
      |                                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:129:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |                     for (int j = 0; j < possible_additional_edges[r].size(); j++){
      |                                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
simurgh.cpp:143:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |     for (int i = 0; i < decided.size(); i++){
      |                     ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 0 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 0 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 0 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 0 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 3 ms 384 KB correct
15 Correct 3 ms 384 KB correct
16 Correct 3 ms 384 KB correct
17 Correct 3 ms 384 KB correct
18 Correct 2 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 384 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 256 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 256 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 384 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 384 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 0 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 0 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 3 ms 384 KB correct
15 Correct 3 ms 384 KB correct
16 Correct 3 ms 384 KB correct
17 Correct 3 ms 384 KB correct
18 Correct 2 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 384 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 256 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 256 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 384 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 384 KB correct
34 Correct 213 ms 1656 KB correct
35 Correct 224 ms 1536 KB correct
36 Correct 152 ms 1436 KB correct
37 Correct 13 ms 384 KB correct
38 Correct 225 ms 1536 KB correct
39 Correct 196 ms 1536 KB correct
40 Correct 154 ms 1528 KB correct
41 Correct 219 ms 1536 KB correct
42 Correct 216 ms 1784 KB correct
43 Correct 119 ms 1272 KB correct
44 Correct 97 ms 952 KB correct
45 Correct 132 ms 896 KB correct
46 Correct 81 ms 896 KB correct
47 Correct 40 ms 640 KB correct
48 Correct 7 ms 384 KB correct
49 Correct 13 ms 384 KB correct
50 Correct 40 ms 640 KB correct
51 Correct 114 ms 1016 KB correct
52 Correct 95 ms 1016 KB correct
53 Correct 79 ms 888 KB correct
54 Correct 119 ms 1104 KB correct
55 Correct 114 ms 1028 KB correct
56 Correct 110 ms 1024 KB correct
57 Correct 110 ms 1024 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Incorrect 170 ms 3712 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 0 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 0 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 3 ms 384 KB correct
15 Correct 3 ms 384 KB correct
16 Correct 3 ms 384 KB correct
17 Correct 3 ms 384 KB correct
18 Correct 2 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 2 ms 384 KB correct
23 Correct 2 ms 384 KB correct
24 Correct 2 ms 384 KB correct
25 Correct 1 ms 256 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 256 KB correct
30 Correct 2 ms 384 KB correct
31 Correct 2 ms 384 KB correct
32 Correct 2 ms 384 KB correct
33 Correct 2 ms 384 KB correct
34 Correct 213 ms 1656 KB correct
35 Correct 224 ms 1536 KB correct
36 Correct 152 ms 1436 KB correct
37 Correct 13 ms 384 KB correct
38 Correct 225 ms 1536 KB correct
39 Correct 196 ms 1536 KB correct
40 Correct 154 ms 1528 KB correct
41 Correct 219 ms 1536 KB correct
42 Correct 216 ms 1784 KB correct
43 Correct 119 ms 1272 KB correct
44 Correct 97 ms 952 KB correct
45 Correct 132 ms 896 KB correct
46 Correct 81 ms 896 KB correct
47 Correct 40 ms 640 KB correct
48 Correct 7 ms 384 KB correct
49 Correct 13 ms 384 KB correct
50 Correct 40 ms 640 KB correct
51 Correct 114 ms 1016 KB correct
52 Correct 95 ms 1016 KB correct
53 Correct 79 ms 888 KB correct
54 Correct 119 ms 1104 KB correct
55 Correct 114 ms 1028 KB correct
56 Correct 110 ms 1024 KB correct
57 Correct 110 ms 1024 KB correct
58 Correct 0 ms 256 KB correct
59 Correct 0 ms 256 KB correct
60 Incorrect 170 ms 3712 KB WA in grader: NO
61 Halted 0 ms 0 KB -