diff --git a/EOF b/EOF deleted file mode 100644 index e69de29..0000000 diff --git a/src/9/2/P1967.cpp b/src/9/2/P1967.cpp new file mode 100644 index 0000000..21ae23b --- /dev/null +++ b/src/9/2/P1967.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include +#include + +using ll = int64_t; + +struct Edge{ + ll to{}; + ll w{}; + inline bool operator<(const Edge&r){ + return w> edg; +std::vector unf; +std::priority_queue pq; +ll mergednum = 0; + +static inline ll find(ll idx){ + if(idx==unf[idx])return idx; + return unf[idx]=find(unf[idx]); +} + +static inline void merge(ll a,ll b){ + unf[find(a)]=find(b); +} + +static inline bool ismerged(ll a,ll b){ + return find(a)==find(b); +} + +int main(){ + std::ios_base::sync_with_stdio(false); + std::cin.tie(nullptr); + + std::cin>>n>>m; + + edg.resize(n+1); + unf.resize(n+1); + + for(ll i=1;i<=n;i++){ + ll x,y,z; + std::cin>>x>>y>>z; + pq.emplace(x,y,z); + } + + while(pq.size() && mergednum < n-1){ + auto[x,y,z] = pq.top(); + pq.pop(); + if(ismerged(x, y))continue; + edg[x].emplace_back(y,z); + edg[y].emplace_back(x,z); + merge(x, y); + mergednum++; + } + + for(ll u=1;u<=n;u++){ + for(auto [v,w]:edg[u]){ + char buff[128]; + memset(buff, 0, sizeof(buff)); + sprintf(buff,"point %lld to %lld weight %lld\n",u,v,w); + std::cout<