結果
問題 | No.2888 Mamehinata |
ユーザー | Fu_L |
提出日時 | 2024-09-26 08:52:43 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 3,012 bytes |
コンパイル時間 | 3,831 ms |
コンパイル使用メモリ | 289,116 KB |
実行使用メモリ | 21,748 KB |
最終ジャッジ日時 | 2024-09-26 08:52:59 |
合計ジャッジ時間 | 9,515 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 30 ms
8,576 KB |
testcase_14 | AC | 18 ms
8,064 KB |
testcase_15 | AC | 87 ms
16,128 KB |
testcase_16 | AC | 99 ms
17,240 KB |
testcase_17 | AC | 17 ms
9,216 KB |
testcase_18 | AC | 47 ms
11,392 KB |
testcase_19 | AC | 113 ms
18,480 KB |
testcase_20 | AC | 95 ms
16,188 KB |
testcase_21 | AC | 93 ms
16,148 KB |
testcase_22 | AC | 34 ms
11,648 KB |
testcase_23 | AC | 44 ms
14,432 KB |
testcase_24 | AC | 96 ms
17,704 KB |
testcase_25 | AC | 65 ms
16,552 KB |
testcase_26 | AC | 68 ms
16,232 KB |
testcase_27 | AC | 31 ms
12,720 KB |
testcase_28 | AC | 17 ms
5,888 KB |
testcase_29 | AC | 41 ms
9,600 KB |
testcase_30 | AC | 114 ms
18,716 KB |
testcase_31 | AC | 93 ms
16,144 KB |
testcase_32 | AC | 59 ms
12,316 KB |
testcase_33 | AC | 85 ms
15,232 KB |
testcase_34 | AC | 70 ms
13,216 KB |
testcase_35 | AC | 64 ms
11,904 KB |
testcase_36 | AC | 128 ms
19,916 KB |
testcase_37 | AC | 131 ms
20,480 KB |
testcase_38 | AC | 29 ms
8,064 KB |
testcase_39 | AC | 94 ms
17,152 KB |
testcase_40 | AC | 127 ms
20,076 KB |
testcase_41 | AC | 18 ms
6,272 KB |
testcase_42 | AC | 100 ms
17,720 KB |
testcase_43 | AC | 86 ms
18,116 KB |
testcase_44 | AC | 95 ms
19,688 KB |
testcase_45 | AC | 116 ms
21,748 KB |
testcase_46 | AC | 14 ms
5,556 KB |
testcase_47 | AC | 90 ms
19,328 KB |
testcase_48 | AC | 79 ms
16,532 KB |
testcase_49 | AC | 11 ms
6,016 KB |
testcase_50 | AC | 34 ms
12,544 KB |
testcase_51 | AC | 3 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 6 ms
5,376 KB |
testcase_54 | AC | 1 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, a, b) for(ll i = a; i < b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) constexpr ll inf = 4e18; struct SetupIO { SetupIO() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(30); } } setup_io; template <typename T> struct Edge { int from, to; T cost; int idx; Edge() : from(-1), to(-1), cost(-1), idx(-1) {} Edge(int from, int to, const T& cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {} operator int() const { return to; } }; template <typename T> struct Graph { Graph(int N) : n(N), es(0), g(N) {} int size() const { return n; } int edge_size() const { return es; } void add_edge(int from, int to, const T& cost = 1) { assert(0 <= from and from < n); assert(0 <= to and to < n); g[from].emplace_back(from, to, cost, es); g[to].emplace_back(to, from, cost, es++); } void add_directed_edge(int from, int to, const T& cost = 1) { assert(0 <= from and from < n); assert(0 <= to and to < n); g[from].emplace_back(from, to, cost, es++); } inline vector<Edge<T>>& operator[](const int& k) { assert(0 <= k and k < n); return g[k]; } inline const vector<Edge<T>>& operator[](const int& k) const { assert(0 <= k and k < n); return g[k]; } private: int n, es; vector<vector<Edge<T>>> g; }; template <typename T> using Edges = vector<Edge<T>>; template <typename T> vector<pair<T, int>> dijkstra(const Graph<T>& g, const int s = 0) { const int n = g.size(); assert(0 <= s and s < n); vector<pair<T, int>> d(n, {numeric_limits<T>::max(), -1}); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq; d[s] = {0, -1}; pq.emplace(0, s); while(!pq.empty()) { const auto [dist, cur] = pq.top(); pq.pop(); if(d[cur].first < dist) continue; for(const Edge<T>& e : g[cur]) { if(d[e.to].first > d[cur].first + e.cost) { d[e.to] = {d[cur].first + e.cost, cur}; pq.emplace(d[e.to].first, e.to); } } } return d; } int main(void) { int n, m; cin >> n >> m; Graph<int> g(n); rep(i, 0, m) { int u, v; cin >> u >> v; u--; v--; g.add_edge(u, v); } vector<pair<int, int>> d = dijkstra(g, 0); vector<int> ans(n + 1); int cnt = 0; rep(i, 0, n) { if(d[i].first == numeric_limits<int>::max()) continue; ans[d[i].first]++; cnt++; } if(cnt == 1) { rep(i, 1, n + 1) { cout << 0 << '\n'; } return 0; } rep(i, 1, n + 1) { if(i >= 2) { ans[i] += ans[i - 2]; } cout << ans[i] << '\n'; } }