結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 205 ms
12,084 KB
testcase_05 AC 203 ms
12,112 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 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 12 ms
4,380 KB
testcase_31 AC 95 ms
10,100 KB
testcase_32 AC 82 ms
9,380 KB
testcase_33 AC 53 ms
7,176 KB
testcase_34 AC 67 ms
8,664 KB
testcase_35 AC 53 ms
7,356 KB
testcase_36 AC 12 ms
4,376 KB
testcase_37 AC 16 ms
4,736 KB
testcase_38 AC 85 ms
9,384 KB
testcase_39 AC 34 ms
5,832 KB
testcase_40 AC 35 ms
5,804 KB
testcase_41 AC 71 ms
8,956 KB
testcase_42 AC 40 ms
6,324 KB
testcase_43 AC 42 ms
6,444 KB
testcase_44 AC 41 ms
6,328 KB
testcase_45 AC 30 ms
5,608 KB
testcase_46 AC 13 ms
4,460 KB
testcase_47 AC 9 ms
4,376 KB
testcase_48 AC 88 ms
9,644 KB
testcase_49 AC 5 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 WA -
testcase_52 AC 248 ms
11,096 KB
testcase_53 AC 247 ms
11,084 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 + 3;
  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