結果

問題 No.1640 簡単な色塗り
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-08 16:41:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 2,062 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 212,660 KB
実行使用メモリ 21,844 KB
最終ジャッジ日時 2023-09-12 04:02:43
合計ジャッジ時間 17,659 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 231 ms
21,772 KB
testcase_05 AC 243 ms
21,844 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 170 ms
13,852 KB
testcase_11 AC 146 ms
12,176 KB
testcase_12 AC 127 ms
10,968 KB
testcase_13 AC 299 ms
19,840 KB
testcase_14 AC 297 ms
19,532 KB
testcase_15 AC 86 ms
8,848 KB
testcase_16 AC 107 ms
10,240 KB
testcase_17 AC 230 ms
17,148 KB
testcase_18 AC 19 ms
4,420 KB
testcase_19 AC 120 ms
11,200 KB
testcase_20 AC 175 ms
13,608 KB
testcase_21 AC 143 ms
11,592 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 199 ms
14,608 KB
testcase_24 AC 48 ms
6,520 KB
testcase_25 AC 127 ms
11,040 KB
testcase_26 AC 218 ms
16,120 KB
testcase_27 AC 82 ms
8,544 KB
testcase_28 AC 275 ms
19,016 KB
testcase_29 AC 214 ms
15,980 KB
testcase_30 AC 19 ms
5,880 KB
testcase_31 AC 176 ms
21,384 KB
testcase_32 AC 142 ms
19,068 KB
testcase_33 AC 91 ms
13,900 KB
testcase_34 AC 120 ms
17,068 KB
testcase_35 AC 95 ms
13,684 KB
testcase_36 AC 20 ms
5,968 KB
testcase_37 AC 27 ms
7,152 KB
testcase_38 AC 157 ms
19,560 KB
testcase_39 AC 55 ms
10,328 KB
testcase_40 AC 62 ms
10,344 KB
testcase_41 AC 125 ms
17,408 KB
testcase_42 AC 67 ms
11,364 KB
testcase_43 AC 66 ms
11,544 KB
testcase_44 AC 68 ms
11,408 KB
testcase_45 AC 47 ms
9,680 KB
testcase_46 AC 22 ms
6,252 KB
testcase_47 AC 14 ms
5,072 KB
testcase_48 AC 159 ms
19,956 KB
testcase_49 AC 6 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 300 ms
21,700 KB
testcase_53 AC 309 ms
21,804 KB
07_evil_01.txt AC 748 ms
41,416 KB
07_evil_02.txt AC 1,102 ms
61,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll n;

int main(){
    cin >> n;
    vl ans(n,-1);
    vl a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];a[i]--;b[i]--;
    }
    //set<ll> rem;rep(i,n)rem.insert(i);
    vector<multiset<ll>> deg(n);
    rep(i,n){
        deg[a[i]].insert(i);
        deg[b[i]].insert(i);
    }
    priority_queue<pl,vpl,greater<pl>> que;
    rep(i,n)que.push({deg[i].size(),i});
    vector<ll> comp(n);
    while(!que.empty()){
        auto [hoge,num]=que.top();que.pop();
        if(comp[num]||hoge == 0|| deg[num].empty())continue;
        comp[num]=1;
        ll edge=*deg[num].begin();
        ans[edge]=num;
        deg[a[edge]].erase(deg[a[edge]].find(edge));
        deg[b[edge]].erase(deg[b[edge]].find(edge));
        que.push({deg[a[edge]].size(),a[edge]});
        if(a[edge]!=b[edge])que.push({deg[b[edge]].size(),b[edge]});
    }
    bool ok=true;rep(i,n)if(ans[i]==-1)ok=false;
    cout << (ok? "Yes":"No") <<endl;
    if(ok)rep(i,n)cout << ans[i]+1 <<endl;
    //rep(i,n)cout << ans[i] <<endl;
}      
0