QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#115421 | #6629. Travelling Trader | xtqqwq# | 0 | 1ms | 5988kb | C++14 | 1.5kb | 2023-06-26 09:20:47 | 2024-05-31 14:13:11 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,k,tot;
int v[400005],nxt[400005],h[200005],a[200005];
void addedge(int x,int y){
v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
v[++tot]=x; nxt[tot]=h[y]; h[y]=tot;
}
namespace sub1{
void work(){
}
}
namespace sub2{
void work(){
}
}
namespace sub3{
vector<int> ans;
void dfs(int u,int fa){
for(int p=h[u];p;p=nxt[p]){
if(v[p]==fa) continue;
ans.pb(v[p]);
for(int p1=h[v[p]];p1;p1=nxt[p1]){
if(v[p1]==u) continue;
dfs(v[p1],v[p]);
}
}
ans.pb(u);
}
void work(){
dfs(1,-1);
reverse(ans.begin(),ans.end());
ll res=0;
for(int i=1;i<=n;i++) res+=a[i];
printf("%lld\n",res);
for(auto r:ans) printf("%d ",r);
printf("\n");
}
}
int main(){
n=readint(); k=readint();
for(int i=1;i<n;i++) addedge(readint(),readint());
for(int i=1;i<=n;i++) a[i]=readint();
if(k==1) sub1::work();
else if(k==2) sub2::work();
else if(k==3) sub3::work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5672kb
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: 0
Wrong Answer
time: 0ms
memory: 5732kb
input:
2 2 2 1 243296356 635616793
output:
result:
wrong output format Unexpected end of file - int64 expected
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #83:
score: 0
Wrong Answer
time: 0ms
memory: 5988kb
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:
1008611451196 1 379 1954 1539 605 1613 1300 1823 1101 1840 562 867 709 88 916 1526 1238 129 1919 816 674 1788 832 297 1903 1349 1808 1428 183 863 951 1522 877 301 775 1265 936 1087 1672 565 1963 1330 926 1325 524 1334 36 46 1019 1231 240 665 1376 289 1427 545 1076 1880 1684 1668 81 1504 1373 1987 11...
result:
wrong answer your path must start at vertex 1
Subtask #6:
score: 0
Skipped
Dependency #5:
0%