Submission #1372331


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);
  }
  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 > 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 1327 Byte
Status WA
Exec Time 512 ms
Memory 8832 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 3
AC × 24
WA × 15
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 AC 430 ms 6264 KB
binary_02.txt AC 163 ms 4992 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 162 ms 4992 KB
kary_02.txt AC 354 ms 5120 KB
kary_03.txt AC 157 ms 4480 KB
line_01.txt AC 187 ms 6528 KB
line_02.txt AC 348 ms 7168 KB
line_03.txt AC 348 ms 7168 KB
line_04.txt AC 383 ms 8832 KB
line_05.txt AC 162 ms 6528 KB
line_06.txt AC 190 ms 6528 KB
random0_01.txt AC 236 ms 5376 KB
random1_01.txt WA 365 ms 6528 KB
random1_02.txt WA 365 ms 6400 KB
random1_03.txt WA 374 ms 6272 KB
random1_04.txt WA 436 ms 6016 KB
random1_05.txt WA 359 ms 6528 KB
random1_06.txt WA 363 ms 6528 KB
random1_07.txt WA 376 ms 6400 KB
random1_08.txt AC 512 ms 6016 KB
random2_01.txt AC 162 ms 5376 KB
random2_02.txt WA 359 ms 6528 KB
random2_03.txt WA 361 ms 6528 KB
random2_04.txt WA 365 ms 6400 KB
random2_05.txt AC 246 ms 5376 KB
random2_06.txt AC 320 ms 5376 KB
random3_01.txt WA 361 ms 6528 KB
random3_02.txt WA 447 ms 6016 KB
random4_01.txt WA 359 ms 6528 KB
random4_02.txt WA 363 ms 6528 KB
random4_03.txt WA 358 ms 6528 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 AC 399 ms 4600 KB
star_02.txt AC 202 ms 3960 KB