結果

問題 No.1640 簡単な色塗り
ユーザー kiyoshi0205kiyoshi0205
提出日時 2021-08-06 23:13:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 178,332 KB
実行使用メモリ 18,224 KB
最終ジャッジ日時 2023-09-12 03:09:38
合計ジャッジ時間 11,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 39 ms
14,232 KB
testcase_05 AC 45 ms
18,200 KB
testcase_06 AC 1 ms
4,376 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 43 ms
12,004 KB
testcase_11 AC 31 ms
10,300 KB
testcase_12 AC 30 ms
9,692 KB
testcase_13 AC 73 ms
16,752 KB
testcase_14 AC 83 ms
16,820 KB
testcase_15 AC 24 ms
7,800 KB
testcase_16 AC 29 ms
8,800 KB
testcase_17 AC 62 ms
14,324 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 32 ms
9,708 KB
testcase_20 AC 44 ms
11,896 KB
testcase_21 AC 34 ms
10,160 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 46 ms
12,740 KB
testcase_24 AC 13 ms
5,624 KB
testcase_25 AC 34 ms
9,908 KB
testcase_26 AC 51 ms
13,488 KB
testcase_27 AC 24 ms
7,696 KB
testcase_28 AC 84 ms
16,224 KB
testcase_29 AC 53 ms
13,320 KB
testcase_30 AC 10 ms
5,368 KB
testcase_31 AC 75 ms
18,084 KB
testcase_32 AC 64 ms
15,848 KB
testcase_33 AC 36 ms
11,880 KB
testcase_34 AC 45 ms
14,124 KB
testcase_35 AC 44 ms
11,704 KB
testcase_36 AC 9 ms
5,360 KB
testcase_37 AC 13 ms
6,280 KB
testcase_38 AC 57 ms
16,484 KB
testcase_39 AC 25 ms
8,920 KB
testcase_40 AC 26 ms
9,108 KB
testcase_41 AC 48 ms
14,264 KB
testcase_42 AC 30 ms
9,952 KB
testcase_43 AC 32 ms
10,176 KB
testcase_44 AC 29 ms
9,840 KB
testcase_45 AC 22 ms
8,260 KB
testcase_46 AC 10 ms
5,348 KB
testcase_47 AC 7 ms
4,556 KB
testcase_48 AC 68 ms
16,948 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 68 ms
18,148 KB
testcase_53 AC 70 ms
18,224 KB
07_evil_01.txt AC 240 ms
33,972 KB
07_evil_02.txt AC 409 ms
49,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;++i)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int i,j=0,a,b,N;
  cin>>N;
  vector<int> ab(N,0),ans(N,0),vis(N,0);
  vector<set<int>> edgelist(N);
  rep(i,N){
    cin>>a>>b;
    edgelist[--a].emplace(i);
    edgelist[--b].emplace(i);
    ab[i]=a^b;
  }
  queue<int> que;
  rep(i,N)if(edgelist[i].size()==1)que.emplace(i);
  do{
    while(!que.empty()){
      a=que.front();que.pop();
      if(edgelist[a].size()==0){
        puts("No");
        return 0;
      }
      i=*edgelist[a].begin();
      edgelist[a].erase(edgelist[a].begin());
      vis[a]=1;
      ans[i]=a+1;
      b=ab[i]^a;
      edgelist[b].erase(i);
      if(edgelist[b].size()==1)que.emplace(b);
    }
    while(j<N&&vis[j])++j;
    if(j<N)que.emplace(j);
    else{
      cout<<"Yes\n";
      for(auto& x:ans)cout<<x<<'\n';
      return 0;
    }
  }while(1);
}
0