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>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
using namespace std;
ll n,m,k,start;
ll a[105][1005],b[105][1005];
bool vis[105];
vector<pair<ll,ll> >v[105];
vector<pair<vector<ll>,ll> >loop;
vector<ll>temp;
set<set<ll> >check;
void dfs(ll t,ll parent,ll cost){
temp.pb(t);
if(t==start and temp.size()>1){
temp.erase(temp.end()-1);
set<ll>st;
for(auto i:temp){
st.insert(i);
}
temp.pb(t);
if(check.find(st)==check.end()){
check.insert(st);
loop.pb({temp,cost});
}
}
vis[t]=1;
vis[start]=0;
for(auto i:v[t]){
if(!vis[i.f] and i.f!=parent){
cost+=i.s;
dfs(i.f,t,cost);
cost-=i.s;
}
}
temp.erase(temp.end()-1);
vis[t]=0;
}
int main(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
for(int c=1;c<=k;c++){
cin>>a[i][c]>>b[i][c];
//a--> buy price
//b--> sell price
}
}
ll x,y,w;
for(int i=0;i<m;i++){
cin>>x>>y>>w;
v[x].pb({y,w});
}
for(int i=1;i<=n;i++){
start=i;
dfs(i,0,0);
for(int c=1;c<=n;c++){
vis[c]=0;
}
}
for(int i=0;i<loop.size();i++){
ll dp[n+5][k+5];
for(int e=1;e<loop[i].f.size();e++){
for(int c=1;c<=k;c++){
dp[loop[i].f[e]][c]=0;
}
}
for(int c=1;c<loop[i].f.size();c++){
ll t=loop[i].f[c];
for(int j=1;j<=k;j++){
if(b[t][j]==-1){
continue;
}
ll maks=0;
for(int q=1;q<t;q++){
for(int e=1;e<=k;e++){
maks=max(maks,dp[t-q][e]);
}
if(a[t-q][j]==-1){
continue;
}
dp[t][j]=max(dp[t][j],maks-a[t-q][j]+b[t][j]);
}
}
}
cout<<dp[n][1]<<" "<<dp[n][2]<<endl;
}
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int main()':
merchant.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::vector<long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<loop.size();i++){
| ~^~~~~~~~~~~~
merchant.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int e=1;e<loop[i].f.size();e++){
| ~^~~~~~~~~~~~~~~~~
merchant.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int c=1;c<loop[i].f.size();c++){
| ~^~~~~~~~~~~~~~~~~
# | 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... |