ans
071maozihan
2022-04-30 8:42:35
15
返回题目
#include <bits/stdc++.h>
#define int long long
const long long maxn = 2e2 + 10;
using namespace std;
int n;
int dp[maxn], a[maxn];
string s[maxn];
vector<int> v[maxn];
string zhuanhuan(int x) {
string st1, st2;
while (x > 0) {
st1 += (char)(x % 10 + '0');
x /= 10;
}
for (int i = st1.size() - 1; i >= 0; i--) {
st2 += st1[i];
}
return st2;
}
void DFS(int deep, int cnt, string tmp) {
if (cnt < dp[deep])
return;
dp[deep] = cnt;
s[deep] = tmp;
for (int i = 0; i < v[deep].size(); i++) {
DFS(v[deep][i], cnt + a[v[deep][i]], tmp + '-' + zhuanhuan(v[deep][i]));
}
}
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[i] = a[i];
}
int x, y;
while (cin >> x >> y && x != 0 && y != 0) {
v[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
string t = zhuanhuan(i);
DFS(i, a[i], t);
}
int ans = INT_MIN, id;
for (int i = 1; i <= n; i++) {
if (ans < dp[i]) {
ans = dp[i];
id = i;
}
}
cout << s[id] << endl;
cout << ans;
return 0;
}
{{ vote && vote.total.up }}