結果
問題 | No.812 Change of Class |
ユーザー | null_null |
提出日時 | 2019-04-21 18:03:49 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,530 bytes |
コンパイル時間 | 2,025 ms |
コンパイル使用メモリ | 177,072 KB |
実行使用メモリ | 11,528 KB |
最終ジャッジ日時 | 2024-06-12 20:55:10 |
合計ジャッジ時間 | 9,499 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 6 ms
6,940 KB |
testcase_08 | AC | 6 ms
6,940 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 19 ms
7,992 KB |
testcase_12 | WA | - |
testcase_13 | AC | 5 ms
6,940 KB |
testcase_14 | AC | 6 ms
6,940 KB |
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 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 10 ms
7,136 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | AC | 7 ms
6,944 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | AC | 59 ms
9,996 KB |
testcase_56 | AC | 68 ms
10,648 KB |
testcase_57 | AC | 72 ms
11,024 KB |
testcase_58 | AC | 40 ms
8,756 KB |
testcase_59 | AC | 80 ms
11,528 KB |
testcase_60 | AC | 5 ms
6,940 KB |
testcase_61 | AC | 4 ms
6,944 KB |
testcase_62 | AC | 5 ms
6,944 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 = bfs(a); if (day - 1 != 0) { day = (day + 1) / 2; } else { day = 0; } cout << uf.size(a) - 1 << " " << day << endl; } return 0; }