結果

問題 No.1640 簡単な色塗り
ユーザー bit_kyoprobit_kyopro
提出日時 2021-08-06 22:19:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,871 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 176,088 KB
実行使用メモリ 814,520 KB
最終ジャッジ日時 2023-09-12 02:14:15
合計ジャッジ時間 5,191 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 207 ms
12,564 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
07_evil_01.txt -- -
07_evil_02.txt -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int32_t main()’ 内:
main.cpp:59:18: 警告: 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