結果

問題 No.1640 簡単な色塗り
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-06 21:51:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,023 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 212,368 KB
実行使用メモリ 21,892 KB
最終ジャッジ日時 2023-09-12 01:51:31
合計ジャッジ時間 17,577 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 249 ms
21,832 KB
testcase_05 AC 246 ms
21,892 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 199 ms
13,880 KB
testcase_11 AC 152 ms
11,872 KB
testcase_12 AC 137 ms
10,964 KB
testcase_13 AC 318 ms
19,700 KB
testcase_14 AC 315 ms
19,608 KB
testcase_15 AC 99 ms
8,976 KB
testcase_16 AC 122 ms
10,332 KB
testcase_17 AC 259 ms
17,168 KB
testcase_18 AC 19 ms
4,452 KB
testcase_19 AC 136 ms
11,096 KB
testcase_20 AC 192 ms
13,600 KB
testcase_21 AC 150 ms
11,600 KB
testcase_22 AC 14 ms
4,380 KB
testcase_23 AC 202 ms
14,384 KB
testcase_24 AC 48 ms
6,432 KB
testcase_25 AC 138 ms
11,076 KB
testcase_26 AC 226 ms
16,120 KB
testcase_27 AC 91 ms
8,896 KB
testcase_28 AC 301 ms
19,116 KB
testcase_29 AC 224 ms
16,108 KB
testcase_30 AC 20 ms
5,908 KB
testcase_31 AC 194 ms
21,400 KB
testcase_32 AC 166 ms
19,024 KB
testcase_33 AC 108 ms
13,820 KB
testcase_34 AC 139 ms
16,888 KB
testcase_35 AC 105 ms
13,836 KB
testcase_36 AC 21 ms
5,936 KB
testcase_37 AC 33 ms
7,128 KB
testcase_38 AC 172 ms
19,692 KB
testcase_39 AC 66 ms
10,388 KB
testcase_40 AC 67 ms
10,468 KB
testcase_41 AC 140 ms
17,552 KB
testcase_42 AC 78 ms
11,296 KB
testcase_43 AC 81 ms
11,704 KB
testcase_44 AC 81 ms
11,384 KB
testcase_45 AC 55 ms
9,596 KB
testcase_46 AC 24 ms
6,432 KB
testcase_47 AC 15 ms
5,088 KB
testcase_48 AC 178 ms
20,248 KB
testcase_49 AC 6 ms
4,384 KB
testcase_50 TLE -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
07_evil_01.txt -- -
07_evil_02.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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)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]});
        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