結果
問題 | No.416 旅行会社 |
ユーザー | 👑 AngrySadEight |
提出日時 | 2024-12-05 16:39:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 671 ms / 4,000 ms |
コード長 | 4,517 bytes |
コンパイル時間 | 5,330 ms |
コンパイル使用メモリ | 232,000 KB |
実行使用メモリ | 30,416 KB |
最終ジャッジ日時 | 2024-12-05 16:39:32 |
合計ジャッジ時間 | 14,114 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 348 ms
20,004 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 3 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 11 ms
5,248 KB |
testcase_09 | AC | 50 ms
5,248 KB |
testcase_10 | AC | 369 ms
20,136 KB |
testcase_11 | AC | 343 ms
18,472 KB |
testcase_12 | AC | 336 ms
18,476 KB |
testcase_13 | AC | 344 ms
18,472 KB |
testcase_14 | AC | 657 ms
30,416 KB |
testcase_15 | AC | 662 ms
30,416 KB |
testcase_16 | AC | 616 ms
30,412 KB |
testcase_17 | AC | 660 ms
30,288 KB |
testcase_18 | AC | 671 ms
30,416 KB |
testcase_19 | AC | 483 ms
18,460 KB |
testcase_20 | AC | 481 ms
18,472 KB |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <atcoder/all> #include <bitset> #include <cassert> #include <cmath> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define repk(i, k, n) for (int i = k; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define mod1 1000000007 #define mod2 998244353 #define mod3 100000007 #define vi vector<int> #define vs vector<string> #define vc vector<char> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vector<int>> #define vvc vector<vector<char>> #define vvl vector<vector<ll>> #define vvb vector<vector<bool>> #define vvvi vector<vector<vector<int>>> #define vvvl vector<vector<vector<ll>>> #define pii pair<int, int> #define pil pair<int, ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define vpii vector<pair<int, int>> #define vpll vector<pair<ll, ll>> #define vvpii vector<vector<pair<int, int>>> #define vvpll vector<vector<pair<ll, ll>>> // using mint = modint998244353; template <typename T> void debug(T e) { cerr << e << endl; } template <typename T> void debug(vector<T> &v) { rep(i, v.size()) { cerr << v[i] << " "; } cerr << endl; } template <typename T> void debug(vector<vector<T>> &v) { rep(i, v.size()) { rep(j, v[i].size()) { cerr << v[i][j] << " "; } cerr << endl; } } template <typename T> void debug(vector<pair<T, T>> &v) { rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; } } template <typename T> void debug(set<T> &st) { for (auto itr = st.begin(); itr != st.end(); itr++) { cerr << *itr << " "; } cerr << endl; } template <typename T> void debug(multiset<T> &ms) { for (auto itr = ms.begin(); itr != ms.end(); itr++) { cerr << *itr << " "; } cerr << endl; } template <typename T> void debug(map<T, T> &mp) { for (auto itr = mp.begin(); itr != mp.end(); itr++) { cerr << itr->first << " " << itr->second << endl; } } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << H << " "; debug_out(T...); } int main() { ll N, M, Q; cin >> N >> M >> Q; vector<ll> A(M); vector<ll> B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> C(Q); vector<ll> D(Q); for (ll i = 0; i < Q; i++) { cin >> C[i] >> D[i]; C[i]--; D[i]--; } set<pll> st; for (ll i = 0; i < Q; i++) { st.insert(make_pair(C[i], D[i])); } vector<bool> not_broken(M, false); for (ll i = 0; i < M; i++) { if (st.find(make_pair(A[i], B[i])) == st.end()) { not_broken[i] = true; } } vector<ll> now_ok(N, -1); vector<ll> now_ng(N, Q + 1); for (ll i = 0; i < 20; i++) { vector<vector<ll>> mid_idx(Q + 1, vector<ll>(0)); for (ll j = 0; j < N; j++) { ll mid = (now_ng[j] + now_ok[j]) / 2; if (mid >= 0 && mid <= Q) { mid_idx[mid].push_back(j); } } dsu tree(N); for (ll j = 0; j < M; j++) { if (not_broken[j]) { tree.merge(A[j], B[j]); } } for (ll j = 0; j < mid_idx[Q].size(); j++) { if (tree.same(0, mid_idx[Q][j])) { now_ok[mid_idx[Q][j]] = Q; } else { now_ng[mid_idx[Q][j]] = Q; } } for (ll j = Q - 1; j >= 0; j--) { tree.merge(C[j], D[j]); for (ll k = 0; k < mid_idx[j].size(); k++) { if (tree.same(0, mid_idx[j][k])) { now_ok[mid_idx[j][k]] = j; } else { now_ng[mid_idx[j][k]] = j; } } } // debug(now_ok); // debug(now_ng); } for (ll i = 1; i < N; i++) { if (now_ng[i] == Q + 1) { cout << -1 << endl; } else { cout << now_ng[i] << endl; } } }