이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
struct mode
{
int a,b,w;
}arr[100005];
int sum[200005];
const int INF=1e9;
int main()
{jizz
int n,m,ans=INF;
cin >> n >> m;
for(int i=0;i<m;++i)
{
cin >> arr[i].a >> arr[i].b >> arr[i].w;
if(arr[i].a>arr[i].b)
swap(arr[i].a,arr[i].b);
}
for(int i=(1<<m)-1;i>=0;--i)
{
for(int j=1;j<=n;++j)
sum[j]=0;
for(int j=0;j<m;++j)
if(i>>j&1)
sum[arr[j].a]+=arr[j].w,sum[arr[j].b]-=arr[j].w;
else
sum[1]+=arr[j].w,sum[arr[j].a]-=arr[j].w,sum[arr[j].b]+=arr[j].w;
for(int j=1;j<=n;++j)
sum[j]+=sum[j-1];
ans=min(ans,*max_element(sum+1,sum+n+1));
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |