結果

問題 No.1640 簡単な色塗り
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-30 07:51:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,058 bytes
コンパイル時間 6,151 ms
コンパイル使用メモリ 313,988 KB
実行使用メモリ 13,380 KB
最終ジャッジ日時 2023-08-30 07:52:16
合計ジャッジ時間 19,511 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 64 ms
7,084 KB
testcase_05 AC 78 ms
13,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 53 ms
7,548 KB
testcase_11 AC 42 ms
6,708 KB
testcase_12 AC 37 ms
6,236 KB
testcase_13 AC 80 ms
10,184 KB
testcase_14 AC 81 ms
9,676 KB
testcase_15 AC 27 ms
5,464 KB
testcase_16 AC 33 ms
5,952 KB
testcase_17 AC 66 ms
8,768 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 38 ms
6,224 KB
testcase_20 AC 49 ms
7,288 KB
testcase_21 AC 41 ms
6,624 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 55 ms
7,908 KB
testcase_24 AC 15 ms
4,404 KB
testcase_25 AC 38 ms
6,220 KB
testcase_26 AC 61 ms
8,076 KB
testcase_27 AC 25 ms
5,172 KB
testcase_28 AC 77 ms
9,392 KB
testcase_29 AC 59 ms
8,072 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 99 ms
11,876 KB
testcase_53 AC 91 ms
12,036 KB
07_evil_01.txt AC 200 ms
18,316 KB
07_evil_02.txt AC 373 ms
25,788 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;
  };
  rep(i,n)if(!bo[i]){
    auto [a,b]=v[i];
    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