Submission #88845

# Submission time Handle Problem Language Result Execution time Memory
88845 2018-12-09T08:35:59 Z sailormoon Triumphal arch (POI13_luk) C++14
Compilation error
0 ms 0 KB
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

vector<vector<int>> graph (300001); // size
int visited;

int canHandle(int v, int crs) {
    int num_children = 0, need_crews = 0;

    visited.insert(v);

    for (int i = 0; i < graph[v].size(); i++) {
        if (visited.find(graph[v][i]) == visited.end()) { 
            num_children++;
            need_crews += canHandle(graph[v][i], crs);
        }
    }
    return max(0, num_children + need_crews - crs);
}

int main() { 
    int n, a, b, start = 0, midpoint, end; // n -> towns, a -> from, b -> to
    scanf("%d", &n);
    end = n; // last point
    n--;

    while (n--) {
        scanf("%d %d", &a, &b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    // binary search for sufficient amount of crews
    while (start < end) {
        midpoint = (start + end) / 2;
        if (canHandle(1, midpoint) == 0) 
            end = midpoint;
        else   
            start = ++midpoint; 
        visited.clear();
    }
    printf("%d\n", start);

    return 0;
}

Compilation message

luk.cpp: In function 'int canHandle(int, int)':
luk.cpp:16:13: error: request for member 'insert' in 'visited', which is of non-class type 'int'
     visited.insert(v);
             ^~~~~~
luk.cpp:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < graph[v].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~
luk.cpp:19:21: error: request for member 'find' in 'visited', which is of non-class type 'int'
         if (visited.find(graph[v][i]) == visited.end()) { 
                     ^~~~
luk.cpp:19:50: error: request for member 'end' in 'visited', which is of non-class type 'int'
         if (visited.find(graph[v][i]) == visited.end()) { 
                                                  ^~~
luk.cpp: In function 'int main()':
luk.cpp:46:17: error: request for member 'clear' in 'visited', which is of non-class type 'int'
         visited.clear();
                 ^~~~~
luk.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
luk.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~