QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#486745 | #6629. Travelling Trader | Rafi22 | 0 | 1ms | 3816kb | C++20 | 3.9kb | 2024-07-22 00:04:43 | 2024-07-22 00:04:43 |
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;
const int N=207;
ll p[N];
vector<int>G[N];
int n;
ll DP0[N],DP1[N],DP2[N],DP3[N];
int zkad0a[N],zkad0b[N];
int zkad3a[N],zkad3b[N],zkad3c[N];
int zkad1[N];
int zkad2[N];
int O[N];
void dfs(int v,int o)
{
O[v]=o;
vector<int>X;
ll S=0,T;
for(auto u:G[v])
{
if(u==o) continue;
dfs(u,v);
X.pb(u);
S+=p[u];
}
int m=sz(X);
//policzmy DP0
DP0[v]=p[v];
FOR(i,0,m-1)
{
if(DP3[X[i]]+p[v]>=DP0[v])
{
DP0[v]=DP3[X[i]]+p[v];
zkad0a[v]=X[i];
zkad0b[v]=-1;
}
FOR(j,0,m-1)
{
if(i==j) continue;
T=DP1[X[i]]-p[X[i]]+DP0[X[j]]-p[X[j]]+S+p[v];
if(v==1) debug(X[i],X[j],T,DP1[X[i]],DP0[X[j]]);
if(T>=DP0[v])
{
DP0[v]=T;
zkad0a[v]=X[i];
zkad0b[v]=X[j];
}
}
}
//policzmy DP1
DP1[v]=p[v]+S;
zkad1[v]=-1;
for(auto u:X)
{
T=DP2[u]+p[v];
if(T>=DP1[v])
{
DP1[v]=T;
zkad1[v]=u;
}
}
//policzmy DP2
DP2[v]=p[v]+S;
for(auto u:X)
{
T=DP1[u]-p[u]+p[v]+S;
if(T>=DP2[v])
{
DP2[v]=T;
zkad2[v]=u;
}
}
//policzmy DP3
DP3[v]=p[v];
FOR(i,0,m-1)
{
T=DP3[X[i]]-p[X[i]]+p[v]+S;
if(T>=DP3[v])
{
DP3[v]=T;
zkad3a[v]=X[i];
zkad3b[v]=-1;
zkad3c[v]=-1;
}
FOR(j,0,m-1)
{
if(i==j) continue;
T=DP2[X[i]]-p[X[i]]+DP3[X[j]]-p[X[j]]+p[v]+S;
if(T>=DP3[v])
{
DP3[v]=T;
zkad3a[v]=X[i];
zkad3b[v]=X[j];
zkad3c[v]=-1;
}
FOR(l,0,m-1)
{
if(i==l||j==l) continue;
T=DP2[X[i]]-p[X[i]]+DP1[X[j]]-p[X[j]]+DP0[X[l]]-p[X[l]]+S+p[v];
if(T>=DP3[v])
{
DP3[v]=T;
zkad3a[v]=X[i];
zkad3b[v]=X[j];
zkad3c[v]=X[l];
}
}
}
}
debug(v,DP0[v],DP1[v],DP2[v],DP3[v]);
}
vector<int>ans;
void calc0(int v);
void calc1(int v);
void calc2(int v);
void calc3(int v);
void calc0(int v)
{
debug(v,"0");
if(v==0) return ;
ans.pb(v);
if(zkad0b[v]==-1) calc3(zkad0a[v]);
else
{
calc1(zkad0a[v]);
for(auto u:G[v]) if(u!=O[v]&&u!=zkad0a[v]&&u!=zkad0b[v]) ans.pb(u);
calc0(zkad0b[v]);
}
}
void calc1(int v)
{
debug(v,"1");
if(v==0) return ;
if(zkad1[v]==-1)
{
for(auto u:G[v]) if(u!=O[v]) ans.pb(u);
}
else calc2(zkad1[v]);
ans.pb(v);
}
void calc2(int v)
{
debug(v,"2");
if(v==0) return ;
ans.pb(v);
debug(ans);
calc1(zkad2[v]);
for(auto u:G[v]) if(u!=O[v]&&u!=zkad2[v]) ans.pb(u);
}
void calc3(int v)
{
debug(v,"3");
if(v==0) return ;
if(zkad3b[v]==-1)
{
ans.pb(v);
calc3(zkad3a[v]);
}
else if(zkad3c[v]==-1)
{
for(auto u:G[v]) if(u!=O[v]&&u!=zkad3a[v]&&u!=zkad3b[v]) ans.pb(u);
calc2(zkad3a[v]);
ans.pb(v);
calc3(zkad3b[v]);
}
else
{
calc2(zkad3a[v]);
ans.pb(v);
calc1(zkad3b[v]);
for(auto u:G[v]) if(u!=O[v]&&u!=zkad3a[v]&&u!=zkad3b[v]&&u!=zkad3c[v]) ans.pb(u);
calc0(zkad3c[v]);
}
}
void k2()
{
dfs(1,0);
calc0(1);
//cout<<DP0[1]<<endl;
cout<<DP0[1]<<endl<<sz(ans)<<endl;
for(auto x:ans) cout<<x<<" ";
cout<<endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int k;
cin>>n>>k;
FOR(i,1,n-1)
{
int a,b;
cin>>a>>b;
G[a].pb(b);
G[b].pb(a);
}
FOR(i,1,n) cin>>p[i];
if(k==2) k2();
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3568kb
input:
2 1 1 2 255959470 961356354
output:
result:
wrong output format Unexpected end of file - int64 expected
Subtask #2:
score: 0
Wrong Answer
Test #12:
score: 7
Accepted
time: 0ms
memory: 3580kb
input:
2 2 2 1 243296356 635616793
output:
878913149 2 1 2
result:
ok correct!
Test #13:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
10 2 6 4 3 7 5 10 6 10 8 2 3 9 3 5 4 2 1 4 2 4 2 5 5 4 2 3 4 2
output:
33 10 1 2 8 4 6 10 5 9 3 7
result:
ok correct!
Test #14:
score: -7
Wrong Answer
time: 1ms
memory: 3592kb
input:
200 2 150 170 21 33 96 152 143 26 136 70 92 159 34 164 163 182 74 115 93 61 151 83 81 119 10 146 114 170 39 83 139 4 173 41 193 96 87 57 14 164 107 51 45 15 157 17 43 183 96 30 11 137 55 18 138 81 87 12 112 122 159 82 195 185 75 71 16 191 33 88 70 195 149 114 106 160 96 118 92 44 9 141 107 143 151 2...
output:
51658420977 86 1 89 194 179 151 39 83 135 27 112 40 125 180 120 117 122 33 146 160 13 133 90 106 10 191 196 94 21 88 162 138 193 45 25 78 62 199 36 127 15 99 72 12 159 41 67 173 186 42 116 92 82 197 101 5 32 121 87 29 198 64 26 47 165 50 143 148 75 124 123 49 14 137 54 93 61 19 37 100 3 9 189 8 126 ...
result:
wrong answer your claimed profit is 51658420977 but the profit of your plan is 49951953119
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Runtime Error
Test #83:
score: 0
Runtime Error
input:
2000 3 1359 90 1703 163 158 188 360 1501 195 664 1414 215 1546 1756 536 1096 1726 1223 1150 104 1757 703 1982 282 1023 998 1180 419 576 1759 1496 1993 44 670 1703 952 855 849 1998 1399 1280 980 1533 1090 1270 678 1680 387 469 1734 1799 263 473 588 303 226 5 295 1489 1471 1094 1667 1912 210 1368 1360...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #5:
0%