結果

問題 No.1640 簡単な色塗り
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-30 07:55:20
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 5,750 ms
コンパイル使用メモリ 313,520 KB
実行使用メモリ 13,584 KB
最終ジャッジ日時 2023-08-30 07:55:41
合計ジャッジ時間 17,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 65 ms
7,496 KB
testcase_05 AC 79 ms
13,584 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 52 ms
7,924 KB
testcase_11 AC 43 ms
6,876 KB
testcase_12 AC 38 ms
6,524 KB
testcase_13 AC 82 ms
10,192 KB
testcase_14 AC 79 ms
10,204 KB
testcase_15 AC 27 ms
5,452 KB
testcase_16 AC 33 ms
6,116 KB
testcase_17 AC 85 ms
8,828 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 37 ms
6,512 KB
testcase_20 AC 51 ms
7,548 KB
testcase_21 AC 42 ms
6,860 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 54 ms
7,876 KB
testcase_24 AC 15 ms
4,480 KB
testcase_25 AC 39 ms
6,760 KB
testcase_26 AC 60 ms
8,572 KB
testcase_27 AC 26 ms
5,396 KB
testcase_28 AC 78 ms
9,948 KB
testcase_29 AC 60 ms
8,432 KB
testcase_30 AC 13 ms
4,376 KB
testcase_31 AC 79 ms
12,576 KB
testcase_32 AC 73 ms
11,256 KB
testcase_33 AC 49 ms
8,592 KB
testcase_34 AC 62 ms
10,540 KB
testcase_35 AC 47 ms
8,568 KB
testcase_36 AC 12 ms
4,392 KB
testcase_37 AC 17 ms
5,268 KB
testcase_38 AC 79 ms
10,952 KB
testcase_39 AC 31 ms
6,772 KB
testcase_40 AC 32 ms
6,524 KB
testcase_41 AC 64 ms
9,616 KB
testcase_42 AC 36 ms
6,876 KB
testcase_43 AC 38 ms
7,900 KB
testcase_44 AC 36 ms
7,296 KB
testcase_45 AC 28 ms
6,488 KB
testcase_46 AC 14 ms
4,796 KB
testcase_47 AC 9 ms
4,404 KB
testcase_48 AC 77 ms
11,856 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 104 ms
12,136 KB
testcase_53 AC 95 ms
12,032 KB
07_evil_01.txt AC 220 ms
19,200 KB
07_evil_02.txt AC 373 ms
27,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n;cin>>n;
  vc<pp>v(n); rep(i,n)cin>>v[i].fi>>v[i].se; 
  rep(i,n)v[i].fi--,v[i].se--;
  vc vx(n,vc<pp>(0));
  dsu d(n);
  vc<bool>bo(n,false);
  rep(i,n){
    auto [a,b]=v[i];
    if(!d.same(a,b)){
      d.merge(a,b),bo[i]=true;
      vx[a].pb({b,i}); vx[b].pb({a,i});
    }
  }
  vc<int>ans(n,-1);
  auto f=[&](auto f,int a,int p)->void{
    for(auto [au,i]:vx[a])if(au!=p){
      ans[i]=au;
      f(f,au,a);
    }
    return;
  };
  vc<int>ok(n,0);
  rep(i,n)if(!bo[i]){
    auto [a,b]=v[i];
    if(ok[d.leader(a)])continue;
    ok[d.leader(a)]=1;
    ans[i]=a;
    f(f,a,-1);
  }
  
  rep(i,n)if(ans[i]==-1){
    cout<<"No";
    return 0;
  }
  cout<<"Yes"<<"\n";
  rep(i,n)cout<<ans[i]+1<<"\n";
}
  
0