diff --git a/src/9/10/P9981.cpp b/src/9/10/P9981.cpp new file mode 100644 index 0000000..c01f818 --- /dev/null +++ b/src/9/10/P9981.cpp @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include +using ll = int64_t; + +ll n,m; + +struct Edge{ + ll to,l; +}; +std::vector> edg; +std::vector ind; +std::queue q; +std::vector topo; +std::vector len; +std::vector> lv; + +#define p1v(ind)do{\ + std::cout<<#ind<<"\n";\ + for(auto& i:ind){\ + std::cout<&a,const vector&b){ + if((a.size()|b.size()) == 0){ + return false; + } + if(a.size()==0 && b.size()!=0){ + return true; + } + if(a.size()!=0 && b.size() == 0){ + return false; + } + for(ll i=0;ib[i])return false; + } + return a.size() &v){ + ll res=0; + for(auto i:v){ + res+=i; + } + return res; +} + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + // std::cout<<(std::vector({1,2,2})({1,2,3}))<<"\n"; + std::cin>>n>>m; + edg.resize(n+1); + ind.resize(n+1); + len.resize(n+1); + lv.resize(n+1); + + for(ll i=1;i<=m;i++){ + ll a,b,l; + std::cin>>b>>a>>l; + edg[a].emplace_back(b,l); + ind[b]++; + } + for(ll u=1;u<=n;u++){ + if(ind[u]==0){ + q.emplace(u); + } + } + while(q.size()){ + ll top = q.front(); + q.pop(); + topo.emplace_back(top); + for(auto [to,l]:edg[top]){ + ind[to]--; + if(ind[to]==0){ + q.emplace(to); + // len[to]=std::max(len[to],len[top]+1); + if(len[top]+1>len[to]){ + len[to]=len[top]+1; + lv[to] = lv[top]; + lv[to].emplace_back(l); + }else if(len[to]==len[top]+1){ + std::vector nlv = lv[top]; + nlv.emplace_back(l); + if(lv[to]