結果

問題 No.3552 Triangular Coloring
コンテスト
ユーザー Shymohn _
提出日時 2026-05-22 23:24:10
言語 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
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 2,206 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,360 ms
コンパイル使用メモリ 343,876 KB
実行使用メモリ 28,156 KB
最終ジャッジ日時 2026-05-22 23:24:17
合計ジャッジ時間 5,628 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using u64 = uint64_t;
using pqi = priority_queue<int>;
using dqi = deque<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llrep(i, n) for (LL i = 0; i < (int)(n); i++)
#define nrep(i, s, n) for (int i = s; i < n; i++)
#define drep(i, n) for (int i = (n) - 1; i >= 0; i--;)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mp make_pair
#define int long long
const int INF = 1e17;
const double pi = 3.14159265358979;
const int mod = 998244353;
const int MOD = 1000000007;

//sni:tmp,pi,vvc,no,NO,yes,YES,vi,keta,pq,g

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin>>n>>m;

    vector<vector<int>> path(n);
    vector<int> deg(n, 0);
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        path[u].pb(v);
        path[v].pb(u);
        deg[u]++;
        deg[v]++;
    }

    vector<int> rem;
    vector<bool> removed(n, false);
    queue<int> q;

    rep(i, n) {
        if (deg[i] == 3) q.push(i);
    }

    int nokori = n;
    while (nokori > 3 && !q.empty()) {
        int u = q.front();
        q.pop();

        if (removed[u] || deg[u] != 3) continue;

        removed[u] = true;
        rem.push_back(u);
        nokori--;

        for (int v : path[u]) {
            if (!removed[v]) {
                deg[v]--;
                if (deg[v] == 3) q.push(v);
            }
        }
    }

    vector<int> ans(n,0);
    int c = 1;
    rep(i, n) {
        if (!removed[i]) {
            ans[i] = c++;
        }
    }

    reverse(rem.begin(), rem.end());
    for (int u : rem) {
        vector<bool> used(5, false);
        for (int v : path[u]) {
            if (ans[v] != 0) {
                used[ans[v]] = true;
            }
        }
        nrep(i,1,4)
            if (!used[i]) {
                ans[u] = i;
                break;
            }
        }
        cout << "Yes" << endl;
        rep(i,n) {
        cout << ans[i]+1 << " ";
    }
    cout << endl;
}
    

    
0