結果
| 問題 | No.3552 Triangular Coloring |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-22 23:32:55 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 250 ms / 2,000 ms |
| コード長 | 4,838 bytes |
| 記録 | |
| コンパイル時間 | 4,804 ms |
| コンパイル使用メモリ | 384,604 KB |
| 実行使用メモリ | 45,560 KB |
| 最終ジャッジ日時 | 2026-05-22 23:33:18 |
| 合計ジャッジ時間 | 8,404 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vc vector<char>
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
template<class T, class U>
inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T, class U>
inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// #define ll int
// #define ll int128_t
// #define ll int256_t
// #define ll cpp_int
// constexpr ll inf = (1ll << 60);
// constexpr ll inf = (1 << 30);
// const double PI=3.1415926535897932384626433832795028841971;
// ll rui(ll a,ll b){
// if(b==0)return 1;
// if(b%2==1) return a*rui(a*a,b/2);
// return rui(a*a,b/2);
// }
// vl fact;
// ll kai(ll n){
// fact.resize(n,1);
// rep(i,n-1)fact[i+1]=fact[i]*(i+1);
// }
// using mint = ld;
using mint = modint998244353;//static_modint<998244353>
// using mint = modint1000000007;//static_modint<1000000007>
// using mint = static_modint<922267487>; // 多分落とされにくい NOT ntt-friendly
// using mint = static_modint<469762049>; // ntt-friendly
// using mint = static_modint<167772161>; // ntt-friendly
// using mint = modint;//mint::set_mod(mod);
// ll const mod=1000000007ll;
// ll const mod=998244353ll;
// ll modrui(ll a,ll b,ll mod){
// a%=mod;
// if(b==0)return 1;
// if(b%2==1) return a*modrui(a*a%mod,b/2,mod)%mod;
// return modrui(a*a%mod,b/2,mod)%mod;
// }
// void incr(vl &v,ll n){// n進法
// ll k=v.size();
// v[k-1]++;
// ll now=k-1;
// while (v[now]>=n)
// {
// v[now]=0;
// if(now==0)break;
// v[now-1]++;
// now--;
// }
// return;
// }
// vector<mint> fact,invf;
// void init_modfact(ll sz){
// fact.resize(sz);
// invf.resize(sz);
// fact[0]=1;
// rep(i,sz-1){
// fact[i+1]=fact[i]*(i+1);
// }
// invf[sz-1]=1/fact[sz-1];
// for(ll i=sz-2; i>=0; i--){
// invf[i]=invf[i+1]*(i+1);
// }
// }
// mint choose(ll n,ll r){
// if(n<r || r<0)return 0;
// return fact[n]*invf[r]*invf[n-r];
// }
// vector<mint> modpow,invpow;
// void init_modpow(ll x,ll sz){
// mint inv=1/mint(x);
// modpow.assign(sz,1);
// invpow.assign(sz,1);
// rep(i,sz-1){
// modpow[i+1]=modpow[i]*x;
// invpow[i+1]=invpow[i]*inv;
// }
// }
// long long phi(long long n) {// O(sqrt(n))
// long long res = n;
// for (long long i = 2; i * i <= n; i++) {
// if (n % i == 0) {
// res -= res / i;
// while (n % i == 0) n /= i;
// }
// }
// if (n > 1) res -= res / n;
// return res;
// }
void solve(){
ll n,m;
cin >> n >> m;
vector<pair<ll,ll>> uv(m);
vector<vl> g(n);
for(auto &[u,v]:uv){
cin >> u >> v;
u--;
v--;
g[u].push_back(v);
g[v].push_back(u);
}
if(n==3){
cout << "Yes\n1 2 3\n";
return;
}
vl deg(n,0);
rep(i,n){
deg[i]=g[i].size();
}
vl col(n,-1);
deque<ll> dq;
rep(i,n){
if(deg[i]==3){
dq.push_back(i);
}
}
vl ord(0);
while(!dq.empty()){
ll x=dq.front();
dq.pop_front();
ord.push_back(x);
for(auto to:g[x]){
deg[to]--;
if(deg[to]==3)dq.push_back(to);
}
}
// rep(i,n)cout << ord[i]+1 << " \n"[i==n-1];
vector<vc> ok(n,vc(4,1));
rep(i,n){
ll x=ord[n-1-i];
if(i<4){
col[x]=i;
for(auto to:g[x]){
ok[to][col[x]]=0;
}
continue;
}
rep(c,4)if(ok[x][c])col[x]=c;
for(auto to:g[x]){
ok[to][col[x]]=0;
}
if(col[x]==-1)cout << "wrong\n";
}
cout << "Yes\n";
rep(i,n){
assert(col[i]!=-1);
cout << col[i]+1 << " \n"[i==n-1];
}
for(auto [u,v]:uv){
assert(col[u]!=col[v]);
}
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// ll mx=450;
// vc fl(mx+1,0);
// for(ll d=2;d<=mx;d++){
// if(fl[d])continue;
// ll x=d;
// ps.push_back(x);
// while(x<=mx){
// fl[x]=1;
// x+=d;
// }
// }
ll t = 1;
// cin >> t;
while (t--){
solve();
}
}