結果

問題 No.2888 Mamehinata
ユーザー Jeroen Op de Beek
提出日時 2024-09-13 21:27:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,959 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 208,412 KB
最終ジャッジ日時 2025-02-24 07:10:42
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin >> n >> m;
    vector<array<int,3>> es(m);
    vector<vector<pi>> adj(n);
    for(auto& [u,v,w] : es) {
        cin >> u >> v;
        w=1;
        --u,--v;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    
    auto dijkstra = [&](int s) {
        vector<ll> d(n,oo);
        struct el {
            int at; ll d;
            bool operator<(const el& e) const {
                return d>e.d;
            }
        };
    
    
        priority_queue<el> pq;
        auto push = [&](int at, ll dd) {
            if(d[at]>dd) {
                pq.push({at,dd});
                d[at]=dd;
            }
        };
        push(s,0);
        while(!pq.empty()) {
            auto e = pq.top(); pq.pop();
            if(e.d!=d[e.at]) continue;
            for(auto [to,w] : adj[e.at]) {
                push(to,w+e.d);
            }
        }
        return d;
    };
    auto d = dijkstra(0);
    vi ans(n);
    vi cnt(n+1);
    if(adj[0].size()!=0) {
        for(auto& i : d) if(i<oo) cnt[i]++;
        for(int i=1;i<=n;++i) {
            if(i>=2) cnt[i]+=cnt[i-2];
        }
    }

    cnt.erase(cnt.begin());
    for(auto x : cnt) cout << x << '\n';
    
}
0