Submission #1372340


Source Code Expand

#include <iostream>
#include <vector>
#include <list>

int main() {
  unsigned N;
  std::cin >> N;
  std::vector<std::vector<unsigned>> G(N);
  for (unsigned i = 0; i < N - 1; ++i) {
    unsigned x, y;
    std::cin >> x >> y;
    --x; --y;
    G[std::min(x, y)].push_back(std::max(x, y));
  }
  unsigned K;
  std::cin >> K;
  std::vector<std::pair<int, int>> color(N);
  for (auto &i : color) {
    i.first = std::numeric_limits<int>::min() / 2;
    i.second = std::numeric_limits<int>::max() / 2;
  }
  for (unsigned i = 0; i < K; ++i) {
    unsigned x, y;
    std::cin >> x >> y;
    --x;
    color[x] = std::make_pair(y, y);
  }
  std::vector<int> even_odd(N, -1);
  for (unsigned i = 0; i < N; ++i) {
    if (color[i].first == color[i].second) {
      if (even_odd[i] < 0) {
        even_odd[i] = color[i].first % 2;
      } else {
        if (even_odd[i] != color[i].first % 2) {
          std::cout << "No";
          return 0;
        }
      }
    }
    int x = color[i].first % 2 ? 0 : 1;
    for (auto e : G[i]) {
      if (even_odd[i] < 0) {
        even_odd[i] = x;
      } else {
        if (even_odd[i] == even_odd[e]) {
          std::cout << "No";
          return 0;
        }
      }
    }
  }
  for (unsigned i = N; i-- > 0;) {
    for (auto e : G[i]) {
      color[i].first = std::max(color[i].first, color[e].first - 1);
      color[i].second = std::min(color[i].second, color[e].second + 1);
    }
    if (color[i].first % 2 != even_odd[i]) {
      ++color[i].first;
    }
    if (color[i].second % 2 != even_odd[i]) {
      --color[i].second;
    }
    if (color[i].first > color[i].second) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  for (unsigned i = 0; i < N; ++i) {
    for (auto e : G[i]) {
      if (color[e].first <= color[i].first - 1) {
        color[e].first = color[i].first - 1;
      } else {
        color[e].first = color[i].first + 1;
      }
    }
    std::cout << color[i].first << std::endl;
  }
  return 0;
}

Submission Info

Submission Time
Task E - Integers on a Tree
User ytsmiling
Language C++14 (Clang 3.8.0)
Score 0
Code Size 2089 Byte
Status WA
Exec Time 517 ms
Memory 6912 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 3
AC × 21
WA × 18
Set Name Test Cases
sample sample_01.txt, sample_02.txt, sample_03.txt
All binary_01.txt, binary_02.txt, hand_01.txt, hand_02.txt, hand_03.txt, kary_01.txt, kary_02.txt, kary_03.txt, line_01.txt, line_02.txt, line_03.txt, line_04.txt, line_05.txt, line_06.txt, random0_01.txt, random1_01.txt, random1_02.txt, random1_03.txt, random1_04.txt, random1_05.txt, random1_06.txt, random1_07.txt, random1_08.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random3_01.txt, random3_02.txt, random4_01.txt, random4_02.txt, random4_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, star_01.txt, star_02.txt
Case Name Status Exec Time Memory
binary_01.txt WA 229 ms 5376 KB
binary_02.txt AC 162 ms 5376 KB
hand_01.txt AC 1 ms 256 KB
hand_02.txt AC 1 ms 256 KB
hand_03.txt AC 1 ms 256 KB
kary_01.txt AC 159 ms 5376 KB
kary_02.txt WA 170 ms 4864 KB
kary_03.txt AC 158 ms 4864 KB
line_01.txt AC 188 ms 6912 KB
line_02.txt WA 158 ms 6912 KB
line_03.txt WA 158 ms 6912 KB
line_04.txt WA 190 ms 6912 KB
line_05.txt AC 158 ms 6912 KB
line_06.txt AC 190 ms 6912 KB
random0_01.txt AC 238 ms 5760 KB
random1_01.txt WA 164 ms 5760 KB
random1_02.txt WA 174 ms 5760 KB
random1_03.txt WA 181 ms 5760 KB
random1_04.txt WA 242 ms 5760 KB
random1_05.txt WA 163 ms 5760 KB
random1_06.txt WA 371 ms 6912 KB
random1_07.txt WA 170 ms 5760 KB
random1_08.txt AC 517 ms 6400 KB
random2_01.txt AC 164 ms 5760 KB
random2_02.txt WA 357 ms 6912 KB
random2_03.txt AC 163 ms 5760 KB
random2_04.txt AC 170 ms 5760 KB
random2_05.txt AC 241 ms 5760 KB
random2_06.txt AC 320 ms 5760 KB
random3_01.txt WA 363 ms 6912 KB
random3_02.txt AC 246 ms 5760 KB
random4_01.txt WA 366 ms 6912 KB
random4_02.txt WA 370 ms 6912 KB
random4_03.txt WA 368 ms 6912 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
star_01.txt WA 204 ms 4344 KB
star_02.txt AC 204 ms 4344 KB