This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=310;
const ll inf=2e18;
ll n,m,a[M],b[M],c[M];
bool rev[M];
ll calc(){
for(int i=0;i<n+1;i++)
c[i]=0;
for(int i=0;i<m;i++){
if(rev[i]){
c[1]++;
c[a[i]]--;
c[b[i]]++,c[n+1]--;
}
else{
c[a[i]]++;
c[b[i]]--;
}
}
ll cur=0,res=0;
for(int i=1;i<=n;i++){
cur+=c[i];
res=max(res,cur);
}
return res;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>a[i]>>b[i]>>c[i];
if(a[i]>b[i])
swap(a[i],b[i]);
}
ll ans=inf;
for(int i=0;i<(1<<m);i++){
for(int bit=0;bit<m;bit++){
rev[bit]=((i&(1<<bit))>0);
}
ans=min(ans,calc());
}
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... |