結果
問題 | No.1640 簡単な色塗り |
ユーザー | kwm_t |
提出日時 | 2021-08-07 16:58:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 1,977 bytes |
コンパイル時間 | 3,903 ms |
コンパイル使用メモリ | 232,656 KB |
実行使用メモリ | 13,348 KB |
最終ジャッジ日時 | 2023-09-12 03:52:33 |
合計ジャッジ時間 | 12,042 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,816 KB |
testcase_01 | AC | 3 ms
5,816 KB |
testcase_02 | AC | 3 ms
5,772 KB |
testcase_03 | AC | 3 ms
5,880 KB |
testcase_04 | AC | 38 ms
10,148 KB |
testcase_05 | AC | 44 ms
13,348 KB |
testcase_06 | AC | 3 ms
5,964 KB |
testcase_07 | AC | 3 ms
5,956 KB |
testcase_08 | AC | 3 ms
5,820 KB |
testcase_09 | AC | 3 ms
5,772 KB |
testcase_10 | AC | 32 ms
8,520 KB |
testcase_11 | AC | 27 ms
8,004 KB |
testcase_12 | AC | 25 ms
7,804 KB |
testcase_13 | AC | 49 ms
10,080 KB |
testcase_14 | AC | 49 ms
10,204 KB |
testcase_15 | AC | 19 ms
7,220 KB |
testcase_16 | AC | 22 ms
7,600 KB |
testcase_17 | AC | 40 ms
9,300 KB |
testcase_18 | AC | 6 ms
6,172 KB |
testcase_19 | AC | 23 ms
7,744 KB |
testcase_20 | AC | 31 ms
8,580 KB |
testcase_21 | AC | 26 ms
7,876 KB |
testcase_22 | AC | 5 ms
6,032 KB |
testcase_23 | AC | 34 ms
8,904 KB |
testcase_24 | AC | 12 ms
6,612 KB |
testcase_25 | AC | 24 ms
7,760 KB |
testcase_26 | AC | 36 ms
9,256 KB |
testcase_27 | AC | 18 ms
7,104 KB |
testcase_28 | AC | 45 ms
9,936 KB |
testcase_29 | AC | 38 ms
9,168 KB |
testcase_30 | AC | 8 ms
6,612 KB |
testcase_31 | AC | 38 ms
9,676 KB |
testcase_32 | AC | 35 ms
9,224 KB |
testcase_33 | AC | 24 ms
7,872 KB |
testcase_34 | AC | 29 ms
8,576 KB |
testcase_35 | AC | 24 ms
7,856 KB |
testcase_36 | AC | 8 ms
6,460 KB |
testcase_37 | AC | 10 ms
6,620 KB |
testcase_38 | AC | 35 ms
9,108 KB |
testcase_39 | AC | 16 ms
7,136 KB |
testcase_40 | AC | 17 ms
7,104 KB |
testcase_41 | AC | 30 ms
8,684 KB |
testcase_42 | AC | 18 ms
7,332 KB |
testcase_43 | AC | 19 ms
7,404 KB |
testcase_44 | AC | 19 ms
7,416 KB |
testcase_45 | AC | 15 ms
7,100 KB |
testcase_46 | AC | 9 ms
6,364 KB |
testcase_47 | AC | 7 ms
6,224 KB |
testcase_48 | AC | 36 ms
9,428 KB |
testcase_49 | AC | 4 ms
6,096 KB |
testcase_50 | AC | 3 ms
5,772 KB |
testcase_51 | AC | 3 ms
5,868 KB |
testcase_52 | AC | 57 ms
11,708 KB |
testcase_53 | AC | 57 ms
11,956 KB |
07_evil_01.txt | RE | - |
07_evil_02.txt | RE | - |
ソースコード
#include "bits/stdc++.h" #include "atcoder/all" using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } vector<P>to[100005]; int ans[100005]; bool use[100005]; void dfs(int v, int p = -1) { use[v] = true; for (auto e : to[v]) { int nx = e.first; int id = e.second; if (use[nx])continue; ans[id] = nx; dfs(nx, v); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<P>roop(n, { -1,-1 }); dsu uf(n); rep(i, n) { int a, b; cin >> a >> b; a--; b--; to[a].push_back({ b,i }); to[b].push_back({ a,i }); if (uf.same(a, b)) { if (-1 != roop[uf.leader(a)].first) { cout << "No" << endl; return 0; } ans[i] = min(a, b); roop[uf.leader(a)] = { i ,ans[i] }; } else { int al = uf.leader(a); int bl = uf.leader(b); if ((-1 != roop[al].first) && (-1 != roop[bl].first)) { cout << "No" << endl; return 0; } uf.merge(a, b); int nl = uf.leader(a); if (-1 != roop[al].first)roop[nl] = roop[al]; if (-1 != roop[bl].first)roop[nl] = roop[bl]; } } rep(i, n) { if (i != uf.leader(i))continue; int st = roop[uf.leader(i)].second; dfs(st); } cout << "Yes" << endl; rep(i, n) cout << ans[i] + 1 << endl; return 0; }