#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "job.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e3+50;
const ll mod=1e9+7;
using namespace std;
int n,m,h[nmax],x,y,z,rs,sm,i,j,f[nmax],nr[nmax];
vector<pair<int,int> >a[nmax],g[nmax];
void dfs(int x,int p)
{
h[x]=h[p]+1;
for(int i=0;i<a[x].size();i++)
{
int y=a[x][i].fr,z=a[x][i].sc;
if(y==p || z)continue;
dfs(y,x);
}
}
void rec(int x,int p)
{
for(int i=0;i<g[x].size();i++)
{
int y=g[x][i].fr,z=g[x][i].sc;
if(y==p || z)continue;
rec(y,x);
}
for(int i=0;i<g[x].size();i++)
{
int y=g[x][i].fr,z=g[x][i].sc;
if(h[y]>h[x])continue;
f[y]=max(f[y],f[x]+z);
}
//rs=max(rs,f[x]);
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>x>>y>>z;
a[x].pb(mkp(y,z));
a[y].pb(mkp(x,z));
sm+=z;
if(!z)
{
nr[x]++;
nr[y]++;
}
}
for(i=1;i<=n;i++)if(nr[i]==1)x=i;
dfs(x,0);
for(i=1;i<=n;i++)
{
for(j=0;j<a[i].size();j++)
{
y=a[i][j].fr,z=a[i][j].sc;
if(!z || (h[i]&1)==(h[y]&1))g[i].pb(a[i][j]);
}
}
rec(x,0);
//for(i=1;i<=n;i++)cout<<f[i]<<" ";
//cout<<endl;
cout<<sm-f[x]<<endl;
return 0;
}
/*
5 10
*/
Compilation message
training.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
training.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
training.cpp: In function 'void dfs(int, int)':
training.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<a[x].size();i++)
~^~~~~~~~~~~~
training.cpp: In function 'void rec(int, int)':
training.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[x].size();i++)
~^~~~~~~~~~~~
training.cpp:42:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[x].size();i++)
~^~~~~~~~~~~~
training.cpp: In function 'int main()':
training.cpp:73:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<a[i].size();j++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
628 KB |
Output is correct |
2 |
Correct |
4 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |