結果

問題 No.1640 簡単な色塗り
ユーザー harurunharurun
提出日時 2021-06-12 17:55:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 84,616 KB
最終ジャッジ日時 2025-01-22 07:48:53
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 27 WA * 24 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define ll long long
#define Pll pair<ll,ll>

ostream& operator<<(ostream& os,const vector<pair<ll,pair<ll,ll>>>& a){
  for(pair<ll,pair<ll,ll>> i:a){
    os<<i.first<<" "<<i.second.first<<" "<<i.second.second<<"\n";
  }
  return os;
}

ostream& operator<<(ostream& os,const vector<ll>& a){
  for(ll i:a){
    os<<i<<"\n";
  }
  return os;
}

int main(){
  ll N,a,b;
  cin>>N;
  vector<ll>A(N),B(N),d(N),ans(N),check(N);
  vector<pair<ll,pair<ll,ll>>>tmp;
  for(int i=0;i<N;i++){
    cin>>a>>b;
    A.at(i)=a;
    B.at(i)=b;
    d.at(a-1)++;
    d.at(b-1)++;
  }
  for(ll i=0;i<N;i++){
    tmp.push_back({d.at(A.at(i)-1),{i,A.at(i)}});
    tmp.push_back({d.at(B.at(i)-1),{i,B.at(i)}});
  }
  sort(tmp.begin(),tmp.end());
  cerr<<tmp;
  Pll u;
  for(int i=0;i<2*N;i++){
    u=tmp.at(i).second;
    if(ans.at(u.first)==0 && check.at(u.second-1)==0){
      ans.at(u.first)=u.second;
      check.at(u.second-1)=1;
    }
  }
  cerr<<ans;
  for(int i=0;i<N;i++){
    if(ans.at(i)==0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  for(ll i:ans){
    printf("%lld\n",i);
  }
  return 0;
}
0