結果
問題 | No.317 辺の追加 |
ユーザー |
|
提出日時 | 2023-03-03 14:33:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,244 bytes |
コンパイル時間 | 922 ms |
コンパイル使用メモリ | 95,344 KB |
最終ジャッジ日時 | 2024-11-15 03:32:57 |
合計ジャッジ時間 | 3,244 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:5:10: error: incomplete type 'std::ios' {aka 'std::basic_ios<char>'} used in nested name specifier 5 | ios::sync_with_stdio(false); | ^~~~~~~~~~~~~~~ main.cpp:6:5: error: 'cin' was not declared in this scope 6 | cin.tie(0); | ^~~ main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'? 1 | #include <atcoder/all> +++ |+#include <iostream> 2 | using namespace std; main.cpp:47:33: error: 'cout' was not declared in this scope 47 | for(int i = 1; i <= n; i++) cout << (dp[i] >> 30 ? -1 : dp[i]) << '\n'; | ^~~~ main.cpp:47:33: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
ソースコード
#include <atcoder/all>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);int n, m, u, v;cin >> n >> m;atcoder::dsu uf(n);while(m--){cin >> u >> v;uf.merge(--u, --v);}auto G = uf.groups();vector<int> b;vector<pair<int,int>> a;b.reserve(G.size());a.reserve(G.size());for(auto &&vec : G) b.emplace_back(vec.size());sort(b.begin(), b.end());for(int i = 0; i < b.size(); ){int p = i;while(i < b.size() && b[i] == b[p]) i++;int v = i - p;for(int j = 0; v; j++){if(v >= (1 << j)){v -= 1 << j;a.emplace_back(b[p] * (1 << j), 1 << j);}else{a.emplace_back(b[p] * v, v);v = 0;}}}sort(a.begin(), a.end());vector<int> dp(n + 1, 1 << 30);dp[0] = 0;for(int i = 0, s = 0; i < a.size(); i++){int v, c;tie(v, c) = a[i];for(int j = s; j >= 1; j--){dp[j + v] = min(dp[j + v], dp[j] + c);}dp[v] = min(dp[v], c - 1);s += v;}for(int i = 1; i <= n; i++) cout << (dp[i] >> 30 ? -1 : dp[i]) << '\n';}