Submission #1124862

#TimeUsernameProblemLanguageResultExecution timeMemory
1124862the_ZHERCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
124 ms21840 KiB
#include <bits/stdc++.h> #define int long long #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const int N = 2e5 + 4; const int inf = 1e17; const int mod=998244353; struct edge{ int x,y,c; }; bool cmp(edge a,edge b){ return a.c<=b.c; } vector<pair<int,int> >v[N]; vector<int>v1[N]; vector<edge>v2; int pr[N]; int get(int x){ if(pr[x]==x){ return x; } return pr[x]=get(pr[x]); } void unio(int x,int y){ int a=get(x); int b=get(y); if(a==b){ return ; } pr[a]=b; } int us[N]; int us1[N]; void dfs(int n,int pre){ us[n]=pre; for(int i=0;i<v[n].size();i++){ if(v[n][i].first!=pre){ dfs(v[n][i].first,n); } } } void dfs1(int n,int pre,int cena){ us1[n]=cena; for(int i=0;i<v[n].size();i++){ if(v[n][i].first!=pre){ int cnt=v[n][i].second; for(int j=0;j<v1[n].size();j++){ if(v[n][i].first==v1[n][j]){ cnt=0; } } dfs1(v[n][i].first,n,cena+cnt); } } } signed main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); boost int n,m; cin>>n>>m; int s,t,u,w; cin>>s>>t>>u>>w; for(int i=0;i<m;i++){ int x,y,c; cin>>x>>y>>c; v2.push_back({x,y,c}); } for(int i=1;i<=n;i++){ pr[i]=i; } reverse(v2.begin(),v2.end()); sort(v2.begin(),v2.end(),cmp); for(int i=0;i<v2.size();i++){ int a=get(v2[i].x); int b=get(v2[i].y); int x=v2[i].x; int y=v2[i].y; int c=v2[i].c; if(a!=b){ v[x].push_back({y,c}); v[y].push_back({x,c}); unio(x,y); } } dfs(s,0); int x=t; while(x!=s){ v1[x].push_back(us[x]); v1[us[x]].push_back(x); x=us[x]; } dfs1(u,0,0); cout<<us1[w]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...