結果

問題 No.1640 簡単な色塗り
ユーザー abc3abc3
提出日時 2021-08-07 04:44:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,120 bytes
コンパイル時間 2,884 ms
コンパイル使用メモリ 206,276 KB
実行使用メモリ 5,712 KB
最終ジャッジ日時 2023-09-12 03:41:08
合計ジャッジ時間 11,472 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 148 ms
5,680 KB
testcase_05 AC 146 ms
5,708 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 5 ms
4,380 KB
testcase_31 AC 22 ms
5,364 KB
testcase_32 AC 20 ms
5,080 KB
testcase_33 AC 15 ms
4,608 KB
testcase_34 AC 17 ms
4,800 KB
testcase_35 AC 14 ms
4,376 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 23 ms
5,232 KB
testcase_39 AC 10 ms
4,384 KB
testcase_40 AC 10 ms
4,376 KB
testcase_41 AC 17 ms
4,860 KB
testcase_42 AC 11 ms
4,380 KB
testcase_43 AC 11 ms
4,376 KB
testcase_44 AC 11 ms
4,504 KB
testcase_45 AC 9 ms
4,380 KB
testcase_46 AC 5 ms
4,380 KB
testcase_47 AC 4 ms
4,380 KB
testcase_48 AC 20 ms
5,132 KB
testcase_49 AC 2 ms
4,384 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 WA -
testcase_53 WA -
07_evil_01.txt WA -
07_evil_02.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

   #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const ll INF=1e18;
    const int mod=998244353;

    struct Unionfind{
      vector<int>d;
      Unionfind(int n):d(n,-1){}
      int root(int x){
        if(d[x]<0){return x;}
        return d[x]=root(d[x]);
      }
      bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y){return false;}
        if(d[x]>d[y]){swap(x,y);}
        d[x]+=d[y];
        d[y]=x;
        return true;
      }
      bool same(int x,int y){return root(x)==root(y);}
      int size(int x){return -d[root(x)];}
    };

    void solve(){
        int n;
        cin>>n;
        Unionfind uf(n);
        vector<int>cnt(n);
        vector<int>a(n),b(n);
        
        vector<int>used(n),ans;
        rep(i,n){
            cin>>a[i]>>b[i];
            a[i]--;b[i]--;
            uf.unite(a[i],b[i]);
            if(a[i]==b[i]){ans.push_back(a[i]); used[a[i]]=1; }
        }
        rep(i,n){cnt[uf.root(a[i])]++;}
        
        rep(i,n){
            if(uf.root(i)==i){
                if(cnt[uf.root(i)]<uf.size(i)){
                    cout<<"No"<<endl;
                    return;
                }
            }
            if(used[a[i]]&&used[b[i]]){continue;}
            if(!used[a[i]]){
                used[a[i]]=1;
                ans.push_back(a[i]);
            }
            else{
                used[b[i]]=1;
                ans.push_back(b[i]);
            }
        }
        cout<<"Yes"<<endl;
        rep(i,ans.size()){
            cout<<ans[i]+1<<endl;
        }
    }

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();  

        return 0;
    }
0