I have issue in question named as C. Rumor -893C, link :- https://mirror.codeforces.com/problemset/problem/893/C. I think that i have understand the questions basic as we have to find number of component in graph with minimum price of component and simply we have to do addition i on them. I have come up with pretty good solution but test case 8 getting fail. can you help me where is the problem lies in my code.
include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int solve(){ ll n,m; cin>>n>>m; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i]; for(ll i=0;i<m;i++){ ll x,y; cin>>x>>y; x--;y--; ll t=min(a[x],a[y]); a[x]=t; a[y]=0; } ll res=0; for(ll i=0;i<n;i++) res+=a[i]; cout<<res<<endl; return 0; }
int main(){ ll t=1; //cin>>t; while(t--) solve(); return 0; }
submission link:- https://mirror.codeforces.com/contest/893/submission/167180749. thanks in advance.
Format your code for christsake, no one will read that
The idea is correct but your implementation seems wrong to me.
You have just considered every edge and made one of them equal to
min(first, second)
while making the other one $$$0.$$$ Do you think it will actually work?When you make vertex $$$x$$$ cost = $$$min($$$ $$$c_x$$$, $$$c_y$$$ $$$)$$$ and vertex $$$y$$$ cost = $$$0$$$, you are actually saying that the minimum cost vertex for this component must not be connected to $$$y$$$. (as you made $$$c_y$$$ $$$= 0$$$ which is less than any possible vertex cost.
It's my first time for post so sorry for that
I think you can just remove your code. The submission link is enough. Also if your doubt is resolved just write
[SOLVED]
or[RESOLVED]
at the start of topic so people know your doubt has been cleared.This is my submission: 167158337.