답안 #88892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
88892 2018-12-09T18:34:10 Z sailormoon Triumphal arch (POI13_luk) C++14
0 / 100
322 ms 34004 KB
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
    
using namespace std;
int canHandle(int crs, int v);
vector<vector<int>> graph (1000001); // size
bool visited[1000001];
    
    
int main() { 
    int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
    scanf("%d", &n);
    end = n; // last point

    for (int i = 1; i < n; i++) {
        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;
        for (int i = 0; i < cities; i++) visited[i] = false; // clear array 
        if (canHandle(midpoint, 1) == 0) end = midpoint;
        else start = midpoint + 1; 
    }
    printf("%d\n", start);
    
    return 0;
}
    
int canHandle(int crs, int v) {
    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(graph[v][i], crs);
        }
    }
    if (num_children + need_crews - crs <= 0)
        return 0;
    return num_children + need_crews - crs;
}

Compilation message

luk.cpp: In function 'int canHandle(int, int)':
luk.cpp:38: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:14: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);
         ~~~~~^~~~~~~~~~~~~~~~~
luk.cpp:13:44: warning: 'cities' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
                                            ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 24248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 24888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 27340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 171 ms 30748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 322 ms 34004 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 289 ms 34004 KB Output isn't correct
2 Halted 0 ms 0 KB -