結果

問題 No.1640 簡単な色塗り
ユーザー hayatenhayaten
提出日時 2021-08-07 00:12:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,231 bytes
コンパイル時間 2,589 ms
コンパイル使用メモリ 220,468 KB
実行使用メモリ 12,300 KB
最終ジャッジ日時 2023-09-12 03:34:26
合計ジャッジ時間 16,719 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 204 ms
12,108 KB
testcase_05 AC 205 ms
12,300 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 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 12 ms
4,380 KB
testcase_31 AC 93 ms
10,120 KB
testcase_32 AC 79 ms
9,252 KB
testcase_33 AC 52 ms
7,228 KB
testcase_34 AC 64 ms
8,556 KB
testcase_35 AC 50 ms
7,304 KB
testcase_36 AC 11 ms
4,376 KB
testcase_37 AC 16 ms
4,600 KB
testcase_38 AC 82 ms
9,576 KB
testcase_39 AC 32 ms
5,836 KB
testcase_40 AC 34 ms
5,800 KB
testcase_41 AC 67 ms
8,592 KB
testcase_42 AC 39 ms
6,284 KB
testcase_43 AC 41 ms
6,328 KB
testcase_44 AC 39 ms
6,272 KB
testcase_45 AC 29 ms
5,628 KB
testcase_46 AC 13 ms
4,380 KB
testcase_47 AC 9 ms
4,380 KB
testcase_48 AC 82 ms
9,796 KB
testcase_49 AC 5 ms
4,380 KB
testcase_50 AC 2 ms
4,388 KB
testcase_51 WA -
testcase_52 AC 246 ms
11,164 KB
testcase_53 AC 244 ms
11,448 KB
07_evil_01.txt WA -
07_evil_02.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using namespace atcoder;

using P = pair<int, int>;
using Graph = vector<vector<int>>;
typedef long long ll;
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
Graph G;
bool non_tree[400000];


vector<int> bfs(vector<int> start, int n){
  vector<int> dist(n, 1e9);
  vector<int> pre(n, -1);
  queue<int> que;
  for(auto d : start){
    dist[d] = 0;
    que.push(d);
  }
  while (!que.empty()){
    int v = que.front();
    que.pop();
    for(int u: G[v]){
      if(dist[u] != 1e9) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      que.push(u);
    }
  }
  return dist;
}

int main() {
  int n;
  cin >> n;
  dsu d(n);
  vector<P> res;
  vector<int> cn(n);
  G.resize(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    a--, b--;
    cn[a]++;
    cn[b]++;
    G[a].pb(b);
    G[b].pb(a);
    res.push_back({a, b});
    if(d.same(a, b)){
      non_tree[d.leader(a)] = true;
    }
    if(non_tree[d.leader(a)] | non_tree[d.leader(b)]){
      d.merge(a, b);
      non_tree[d.leader(a)] = true;
    }
    d.merge(a, b);
  }
  int ans = 0;
  rep(i, n){
    if(d.leader(i) != i)continue;
    if(!non_tree[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  int s = -1;
  int e = n;
  rep(i, n){
    chmin(e, cn[i]);
  }
  vector<int> start;
  rep(i, n){
    if(cn[i] == e)start.pb(i);
  }
  vector<int> dist = bfs(start, n);
  cout << "Yes" << endl;
  set<int> st;
  vector<int> used(n, 0);
  rep(i, n){
    int a = res[i].first;
    int b = res[i].second;
    if(used[a] == 0 && used[b] == 0){
      if(dist[a] < dist[b]){
        cout << a + 1 << endl;
        used[a]++;
      }else{
        cout << b + 1 << endl;
        used[b]++;
      }
    }else if(used[b] == 0){
      cout << b + 1 << endl;
      used[b]++;
    }else{
      cout << a + 1 << endl;
      used[a]++;
    }
  }
}
0