結果
問題 | No.812 Change of Class |
ユーザー | null_null |
提出日時 | 2019-04-21 18:21:11 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 195 ms / 4,000 ms |
コード長 | 3,534 bytes |
コンパイル時間 | 1,589 ms |
コンパイル使用メモリ | 174,744 KB |
実行使用メモリ | 11,324 KB |
最終ジャッジ日時 | 2023-09-03 15:13:03 |
合計ジャッジ時間 | 7,852 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
9,360 KB |
testcase_01 | AC | 16 ms
6,992 KB |
testcase_02 | AC | 45 ms
8,308 KB |
testcase_03 | AC | 88 ms
10,068 KB |
testcase_04 | AC | 79 ms
9,796 KB |
testcase_05 | AC | 195 ms
10,352 KB |
testcase_06 | AC | 170 ms
10,124 KB |
testcase_07 | AC | 5 ms
6,644 KB |
testcase_08 | AC | 5 ms
6,624 KB |
testcase_09 | AC | 172 ms
10,676 KB |
testcase_10 | AC | 175 ms
10,616 KB |
testcase_11 | AC | 16 ms
7,836 KB |
testcase_12 | AC | 115 ms
9,936 KB |
testcase_13 | AC | 5 ms
6,744 KB |
testcase_14 | AC | 5 ms
6,736 KB |
testcase_15 | AC | 122 ms
9,056 KB |
testcase_16 | AC | 12 ms
6,736 KB |
testcase_17 | AC | 115 ms
9,436 KB |
testcase_18 | AC | 87 ms
8,528 KB |
testcase_19 | AC | 101 ms
8,956 KB |
testcase_20 | AC | 188 ms
10,384 KB |
testcase_21 | AC | 86 ms
8,448 KB |
testcase_22 | AC | 41 ms
7,340 KB |
testcase_23 | AC | 11 ms
6,720 KB |
testcase_24 | AC | 15 ms
6,836 KB |
testcase_25 | AC | 33 ms
7,188 KB |
testcase_26 | AC | 149 ms
9,896 KB |
testcase_27 | AC | 129 ms
9,436 KB |
testcase_28 | AC | 95 ms
8,896 KB |
testcase_29 | AC | 25 ms
7,136 KB |
testcase_30 | AC | 121 ms
9,220 KB |
testcase_31 | AC | 107 ms
8,840 KB |
testcase_32 | AC | 49 ms
7,620 KB |
testcase_33 | AC | 132 ms
9,668 KB |
testcase_34 | AC | 13 ms
6,772 KB |
testcase_35 | AC | 27 ms
7,384 KB |
testcase_36 | AC | 13 ms
6,800 KB |
testcase_37 | AC | 62 ms
7,844 KB |
testcase_38 | AC | 8 ms
6,864 KB |
testcase_39 | AC | 63 ms
7,928 KB |
testcase_40 | AC | 19 ms
6,984 KB |
testcase_41 | AC | 7 ms
6,836 KB |
testcase_42 | AC | 126 ms
9,156 KB |
testcase_43 | AC | 35 ms
8,168 KB |
testcase_44 | AC | 90 ms
8,436 KB |
testcase_45 | AC | 13 ms
6,792 KB |
testcase_46 | AC | 32 ms
8,120 KB |
testcase_47 | AC | 87 ms
8,336 KB |
testcase_48 | AC | 93 ms
8,776 KB |
testcase_49 | AC | 28 ms
7,244 KB |
testcase_50 | AC | 5 ms
6,708 KB |
testcase_51 | AC | 29 ms
7,396 KB |
testcase_52 | AC | 54 ms
8,448 KB |
testcase_53 | AC | 20 ms
7,040 KB |
testcase_54 | AC | 18 ms
6,968 KB |
testcase_55 | AC | 56 ms
9,784 KB |
testcase_56 | AC | 64 ms
10,604 KB |
testcase_57 | AC | 69 ms
10,724 KB |
testcase_58 | AC | 38 ms
8,708 KB |
testcase_59 | AC | 75 ms
11,324 KB |
testcase_60 | AC | 4 ms
6,580 KB |
testcase_61 | AC | 4 ms
6,512 KB |
testcase_62 | AC | 4 ms
6,524 KB |
ソースコード
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; /*BigInteger #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> namespace xxx = boost::multiprecision; using Bint = xxx::cpp_int; using Real = xxx::number<xxx::cpp_dec_float<1024>>; */ #define int long long #define pb(x) push_back(x) #define m0(x) memset((x), 0, sizeof(x)) #define mm(x) memset((x), -1, sizeof(x)) //container #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end()); #define PERM(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) // debug #define GET_VAR_NAME(variable) #variable #define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl; // bit_macro #define bit(n) (1LL << (n)) #define bitset(a, b) (a) |= (1 << (b)) #define bitunset(a, b) (a) &= ~(1 << (b)) #define bitcheck(a, b) ((((a) >> (b)) & 1) == 1) #define bitcount(a) __builtin_popcountll((a)) //typedef typedef long long lint; typedef unsigned long long ull; typedef complex<long double> Complex; typedef pair<int, int> P; typedef tuple<int, int, int> TP; typedef vector<int> vec; typedef vector<vec> mat; //constant constexpr int INF = (int)1e18; constexpr int MOD = (int)1e9 + 7; constexpr double PI = (double)acos(-1); constexpr double EPS = (double)1e-10; constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1}; constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1}; // template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } // inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // struct Accelerate_Cin { Accelerate_Cin() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; }; struct UnionFind { vector<int> data; UnionFind(int sz) { data.assign(sz, -1); } bool same(int x, int y) { return find(x) == find(y); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; int N, M, Q; vector<int> G[101010]; int bfs(int s) { vec d(101010, INF); vector<bool> vis(101010, 0); d[s] = 0; vis[s] = true; queue<int> q; q.push(s); int ans = 0; while (!q.empty()) { int t = q.front(); q.pop(); for (auto x : G[t]) { if (vis[x] == false) { d[x] = d[t] + 1; vis[x] = true; chmax(ans, d[x]); q.push(x); } } } return ans; } signed main() { cin >> N >> M; UnionFind uf(N); for (int i = 0; i < M; i++) { int p, q; cin >> p >> q; p--, q--; G[p].push_back(q); G[q].push_back(p); uf.unite(p, q); } cin >> Q; while (Q--) { int a; cin >> a; a--; int day = 0; int k = bfs(a); int tmp = 1; while (tmp < k) { tmp *= 2; day++; } cout << uf.size(a) - 1 << " " << day << endl; } return 0; }