답안 #88898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
88898 2018-12-09T18:43:17 Z sailormoon Triumphal arch (POI13_luk) C++14
0 / 100
299 ms 34988 KB
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
    
using namespace std;
int canHandle(int v, int crs, bool visited[]);
vector<vector<int>> graph (1000001); // size
    
    
int main() { 
    int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
    scanf("%d", &n);
    cities = n; // for further usage
    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;
        bool visited[1000001] = { false };
        if (canHandle(1, midpoint, visited) == 0) 
            end = midpoint;
        else   
            start = midpoint + 1; 
    }
    // if (start == 1) start = 0;
    printf("%d\n", start);
    
    return 0;
}
    
int canHandle(int v, int crs, bool visited[]) {
    int num_children = 0, need_crews = 0;
    visited[v] = true;
    for (int i = 0; i < graph[v].size(); i++) {
        if (!visited[graph[v][i]]) { 
            num_children++;
            need_crews += canHandle(crs, graph[v][i], visited);
        }
    }
    if (num_children + need_crews - crs <= 0)
        return 0;
    return num_children + need_crews - crs;
}

Compilation message

luk.cpp: In function 'int main()':
luk.cpp:12:44: warning: variable 'cities' set but not used [-Wunused-but-set-variable]
     int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
                                            ^~~~~~
luk.cpp: In function 'int canHandle(int, int, bool*)':
luk.cpp:41:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < graph[v].size(); i++) {
                     ~~^~~~~~~~~~~~~~~~~
luk.cpp: In function 'int main()':
luk.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
luk.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 24824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 24828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 24872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 24960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 25224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 25988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 28312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 182 ms 31520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 289 ms 34988 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 299 ms 34988 KB Output isn't correct
2 Halted 0 ms 0 KB -