Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : Cable Car TOI12
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 30 July 2022 [09:03]
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int u,v,w;
- bool operator < (const A&o) const{
- return w>o.w;
- }
- };
- int p[100010];
- int fr(int u){
- if(u == p[u]) return u;
- else return p[u] = fr(p[u]);
- }
- vector<A > edges;
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int n,m,u,v,w,st,en,num;
- cin >> n >> m;
- for(int i=1;i<=n;i++)
- p[i] = i;
- for(int i=1;i<=m;i++){
- cin >> u >> v >> w;
- edges.push_back({u,v,w-1});
- }
- cin >> st >> en >> num;
- sort(edges.begin(),edges.end());
- for(auto x:edges){
- int ru = fr(x.u),rv = fr(x.v);
- if(ru == rv) continue;
- p[ru] = rv;
- ru = fr(st),rv = fr(en);
- if(ru == rv){
- cout << (int )ceil((double )num/x.w) << '\n';
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment