|
Problem Description
S two existing city prison, detained a total of N criminals, were No. 1 ~ N. Their relationship naturally very discordant. Among many criminals and even long-standing grudges, if the objective conditions of the conflict could erupt at any time. We use the "grievances value" (a positive integer value) to indicate a degree of animosity between the two criminals, the greater the resentment value, the more rancor between the two criminals. If the value of c grievances two criminals being held in the same prison, friction occurs between the two of them, and the impact force of clashes c.
End of each year, all police stations will be clashes this year in prison by influential arranged in a descending list, and then reported to the Z S City mayor there. Z-busy Mayor influence will only see the first event in the list, if the effect is bad, he will be considered to replace the chief of police.
After detailed examination of the contradictory relationship between N criminals, the police chief felt enormous pressure. He was ready to redistribution of criminals in the two prisons, in order to influence conflicts generated are small, and thus preserve their official positions. Assume that as long as there is hatred in a two criminals in the same prison, then they will be friction at some time of the year. So, how to assign offenders to minimize the impact of conflicts of Z mayor to see? This minimum value is how much?
Input Format
Each line of the input file separated by a space between the two numbers.
The first two acts of positive integers N and M, respectively, represents the number of criminal offenders and hate presence logarithmic.
Each row M rows next three positive integers aj, bj, CJ, indicating the presence of hatred between aj and bj number criminals number, which is anger cj. Data Assurance 1 <= aj <bj <N , 0 <cj <= 1,000,000,000 and each combination offenders appear only once.
Output Format
Total output line, the influence of the clashes is Z mayor to see. If any conflicts occurred in prisons during the year, please output 0.
Sample input
4 6
1 4 2534
2 3 3512
1 2 28351
1 3 6618
2 4 1805
3 4 12884
Sample Output
3512
prompt
Range [] data
has N≤ 15 to 30% of the data.
For 70% of the data have N≤ 2000, M≤ 50000.
To 100% of the data have N≤ 20000, M≤ 100000.
// #include<bits/stdc++.h> using namespace std; #define maxnn 50000 int f[maxnn]; int q; int n,m; struct node { int val,a,b; }yu[300000]; int gf(int v) { return f[v]==v? v: f[v]=gf(f[v]); } bool cmp(node a,node b) { return a.val>b.val; } int main() { cin>>n>>m; for(int i=1;i<=m;i++) { cin>>yu[i].a>>yu[i].b>>yu[i].val; } sort(yu+1,yu+1+m,cmp); for(int i=1;i<=2*n;i++) f[i]=i; for(int i=1;i<=m;i++) { if(gf(yu[i].a)!=gf(yu[i].b)) { f[gf(yu[i].a)]=gf(yu[i].b+n); f[gf(yu[i].b)]=gf(yu[i].a+n); } else { cout<<yu[i].val; exit(0); } } cout<<0; }