Submission #63824111


Source Code Expand

#include <bits/stdc++.h>

#include <atcoder/all>

using namespace atcoder;
using namespace std;
using ll = long long;
// --------------------------------------------------------
template <class T>
bool chmax(T &a, const T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define FOR(i, l, r) for (ll i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (ll i = (r) - 1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0LL)
#define BITCNT(c) __builtin_popcountll(c)
#define SZ(c) ((int)(c).size())
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
template <typename T>
void arrPrint(vector<T> arr) {
  for (auto v : arr) cout << v << " ";
  cout << '\n';
}
template <typename T>
void arrPrint2Dim(vector<vector<T>> arr) {
  for (auto a : arr) arrPrint(a);
}
template <typename T, typename T2>
void arrPrintPair(vector<pair<T, T2>> arr) {
  for (auto v : arr) cout << "{" << v.first << "," << v.second << "}, ";
  cout << '\n';
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// static const int INF = (1 << 30) - 1;  // 1073741824 - 1
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// static const ll MOD = 1000000007;
static const ll MOD = 998244353;
using mint = static_modint<MOD>;
using VM = vector<mint>;
using VVM = vector<VM>;
ostream &operator<<(std::ostream &os, const mint &n) { return os << n.val(); }
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
const ll mx = 200200;
VVLL to(mx);
ll N, K;

// -1で無理, それ以外は今のパスの長さ
ll dfs(ll now, ll p) {
  VLL pathSizes;
  for (ll nex : to[now]) {
    if (nex == p) continue;
    ll v = dfs(nex, now);
    if (v == -1) return -1;
    if (v == 0) continue;
    pathSizes.push_back(v);
  }
  ll res = 0;
  if (SZ(pathSizes) == 0) res = 1;
  if (SZ(pathSizes) == 1) res = pathSizes[0] + 1;
  if (SZ(pathSizes) == 2) {
    res = pathSizes[0] + pathSizes[1] + 1;
    if (res != K) return -1;
    return 0;
  }
  if (SZ(pathSizes) >= 3) return -1;
  res %= K;
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> K;
  ll NK = N * K;
  REP(i, NK - 1) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ll ans = dfs(0, -1);
  if (ans == 0) {
    COUT("Yes");
  } else {
    COUT("No");
  }
}

Submission Info

Submission Time
Task E - Path Decomposition of a Tree
User tinySteLLa
Language C++ 23 (gcc 12.2)
Score 475
Code Size 3318 Byte
Status AC
Exec Time 71 ms
Memory 39024 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 51
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 3 ms 7668 KiB
00_sample_02.txt AC 3 ms 7768 KiB
01_random_01.txt AC 44 ms 15232 KiB
01_random_02.txt AC 43 ms 15232 KiB
01_random_03.txt AC 44 ms 15260 KiB
01_random_04.txt AC 43 ms 15252 KiB
01_random_05.txt AC 46 ms 15224 KiB
01_random_06.txt AC 43 ms 15176 KiB
01_random_07.txt AC 43 ms 15108 KiB
01_random_08.txt AC 43 ms 15176 KiB
01_random_09.txt AC 44 ms 15348 KiB
01_random_10.txt AC 44 ms 15180 KiB
01_random_11.txt AC 44 ms 15320 KiB
01_random_12.txt AC 43 ms 15344 KiB
01_random_13.txt AC 44 ms 15180 KiB
01_random_14.txt AC 43 ms 15236 KiB
01_random_15.txt AC 44 ms 15168 KiB
01_random_16.txt AC 57 ms 14392 KiB
01_random_17.txt AC 59 ms 14464 KiB
01_random_18.txt AC 59 ms 14400 KiB
01_random_19.txt AC 59 ms 15336 KiB
01_random_20.txt AC 44 ms 14180 KiB
01_random_21.txt AC 45 ms 14316 KiB
01_random_22.txt AC 44 ms 14552 KiB
01_random_23.txt AC 49 ms 14396 KiB
01_random_24.txt AC 57 ms 14664 KiB
01_random_25.txt AC 46 ms 14116 KiB
01_random_26.txt AC 57 ms 14908 KiB
01_random_27.txt AC 58 ms 14456 KiB
01_random_28.txt AC 58 ms 14484 KiB
01_random_29.txt AC 56 ms 14376 KiB
01_random_30.txt AC 56 ms 14388 KiB
01_random_31.txt AC 47 ms 14656 KiB
01_random_32.txt AC 49 ms 14804 KiB
01_random_33.txt AC 55 ms 14612 KiB
01_random_34.txt AC 59 ms 14728 KiB
01_random_35.txt AC 48 ms 14908 KiB
01_random_36.txt AC 61 ms 17480 KiB
01_random_37.txt AC 60 ms 19664 KiB
01_random_38.txt AC 59 ms 17904 KiB
01_random_39.txt AC 62 ms 21420 KiB
01_random_40.txt AC 57 ms 21292 KiB
01_random_41.txt AC 54 ms 22096 KiB
01_random_42.txt AC 60 ms 21844 KiB
01_random_43.txt AC 60 ms 19676 KiB
01_random_44.txt AC 60 ms 27336 KiB
01_random_45.txt AC 58 ms 16840 KiB
02_handmade_01.txt AC 2 ms 7744 KiB
02_handmade_02.txt AC 71 ms 39024 KiB
02_handmade_03.txt AC 67 ms 38928 KiB
02_handmade_04.txt AC 34 ms 15808 KiB