結果

問題 No.1640 簡単な色塗り
ユーザー bit_kyopro
提出日時 2021-08-06 22:19:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,871 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 177,416 KB
実行使用メモリ 817,432 KB
最終ジャッジ日時 2024-06-29 15:20:50
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 MLE * 1 -- * 50
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int32_t main()':
main.cpp:59:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   59 |             auto [a,b] = nodes[i];
      |                  ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const long long MOD = 1000000007;
const long double PI = 3.14159265358979;
const long long INF = 1LL<<60;
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
bool is_prime(long long N){if(N==1) return false;for(long long i=2; i*i <= N; i++){if(N%i==0)return false;}return true;}
long long gcd(long long a, long long b){if (b == 0) return a;else return gcd(b, a % b);}
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define int long long

vector<vector<int>> G;
vector<pair<int,int>> nodes;
vector<int> vis, siz;
int d;

int  dfs(int now, int par){
    if(vis[now]){
        return 0;
    }
    int res = 0;
    for(auto v: G[now]){
        if(v==par) continue;
        res += 1+dfs(v,now);
    }
    siz[d]++;
    vis[now] = 1;
    return res;
}

int32_t main(){
    int N; cin >> N;
    G.resize(N);
    vis.resize(N,0);
    siz.resize(N,0);
    for(int i=0; i<N; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        nodes.push_back({a,b});
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bool flag = true;
    for(int i=0; i<N; i++){
        if(vis[i]) continue;
        d = i;
        int ed = dfs(i,-1);
        if(ed<siz[d]) flag = false;
    }
    if(flag==false){
        cout << "No" << endl;
    }else{
        cout <<"Yes" << endl;
        vector<int> nurinuri(N,0);
        for(int i=0; i<N; i++){
            auto [a,b] = nodes[i];
            if(!nurinuri[a]){
                nurinuri[a] = 1;
                cout << a+1 << endl;
            }else{
                nurinuri[b] = 1;
                cout << b+1 << endl;
            }
        }
    }
}
0