結果

問題 No.3552 Triangular Coloring
コンテスト
ユーザー ルク
提出日時 2026-05-08 18:50:03
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,274 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,751 ms
コンパイル使用メモリ 358,980 KB
実行使用メモリ 92,672 KB
最終ジャッジ日時 2026-05-22 21:49:15
合計ジャッジ時間 11,340 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 15 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
constexpr ll dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Init {
  Init() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(15);
  }
} init;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& pair_var) {
  os << pair_var.first << " " << pair_var.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i, vec.size()) {
    os << vec[i];
    if (i != vec.size() - 1) os << " ";
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vec) {
  rep(i, vec.size()) {
    os << vec[i];
    if (i != vec.size() - 1) os << " ";
  }
  return os;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> deg(n);
  vector<vector<ll>> g(n);
  vector<set<int>> g2(n);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
    g2[u].insert(v);
    g2[v].insert(u);
    deg[u]++, deg[v]++;
  }
  queue<int> que;
  rep(i, n) {
    if (deg[i] == 3) {
      que.push(i);
    }
  }
  vector<vector<ll>> vs(n);
  deque<ll> res;
  vector<bool> isDeleted(n);
  int cnt = n;
  while (true) {
    auto x = que.front();
    que.pop();
    res.push_back(x);
    for (auto u : g[x]) {
      vs[x].push_back(u);
    }
    for (auto u : g[x]) {
      if (!isDeleted[u]) {
        deg[u]--;
        g2[x].erase(u);
        g2[u].erase(x);
        if (deg[u] == 3) {
          que.push(u);
        }
      }
    }
    deg[x] = 0;
    g2[x].clear();
    isDeleted[x] = true;
    cnt--;
    if (cnt == 3) break;
  }
  vector<ll> ans(n, -1);
  cout << "Yes" << endl;
  ll k = 1;
  rep(i, n) {
    if (isDeleted[i] == 0) {
      ans[i] = k;
      k++;
    }
  }
  while (!res.empty()) {
    auto x = res.front();
    res.pop_front();
    set<ll> st = {1, 2, 3, 4};
    if (ans[x] == -1) {
      for (auto k : vs[x]) {
        st.erase(ans[k]);
      }
      ans[x] = *st.begin();
    }
  }
  cout << ans << endl;
  return 0;
}
0