记录编号 569040 评测结果 AAAAAAAAAA
题目名称 挖地雷 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-02-13 23:09:48 内存使用 0.00 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <string>
  5. #include <algorithm>
  6. #define OPEN(_x) freopen(#_x".in", "r", stdin); freopen(#_x".out", "w", stdout)
  7. #define ABS(_x) ((_x)<0?(-(_x)):(_x))
  8. #define MAX(_a, _b) ((_a)<(_b)?(_b):(_a))
  9. #define MIN(_a, _b) ((_a)>(_b)?(_b):(_a))
  10. #define fi first
  11. #define se second
  12.  
  13. using namespace std;
  14.  
  15. typedef long long ll;
  16. typedef pair<int, int> PII;
  17.  
  18. namespace IO{
  19. template<typename T>
  20. inline T read() {
  21. T ret=0, sig=1; char ch=0;
  22. while(ch<'0'||ch>'9') { if(ch=='-') sig=-1; ch=getchar(); }
  23. while(ch>='0'&&ch<='9') { ret=(ret<<1)+(ret<<3)+ch-'0'; ch=getchar(); }
  24. return ret*sig;
  25. }
  26. template<typename T>
  27. inline void read(T &x) {
  28. T ret=0, sig=1; char ch=0;
  29. while(ch<'0'||ch>'9') { if(ch=='-') sig=-1; ch=getchar(); }
  30. while(ch>='0'&&ch<='9') { ret=(ret<<1)+(ret<<3)+ch-'0'; ch=getchar(); }
  31. x = ret*sig;
  32. }
  33. template<typename T>
  34. inline void write(T x) {
  35. if(x<0) putchar('-'), x=-x;
  36. T stk[100], tt=0;
  37. do stk[tt++]=x%10, x/=10; while(x);
  38. while(tt) putchar(stk[--tt]+'0');
  39. }
  40. };
  41.  
  42. const int N = 10010;
  43. int a[N], f[N];
  44. int fa[N];
  45. int n;
  46.  
  47. int h[N], ne[N], e[N], idx;
  48. inline void add(int _a, int _b) { e[idx] = _b, ne[idx] = h[_a], h[_a] = idx++; }
  49.  
  50. void dfs(int x) {
  51. if(!x) return;
  52. if(fa[x]) dfs(fa[x]);
  53. IO::write(x), putchar('-');
  54. }
  55.  
  56. int main() {
  57. #ifdef DEBUG
  58. OPEN(test);
  59. #endif
  60. OPEN(landmine);
  61. memset(h, -1, sizeof h);
  62. IO::read(n);
  63. for(register int i = 1; i<=n; ++i) IO::read(a[i]);
  64. int _a, _b;
  65. while(scanf("%d%d", &_a, &_b)==2, _a || _b) add(_b, _a);
  66. int mx = 0;
  67. for(register int i = 1; i<=n; ++i) {
  68. f[i] = a[i];
  69. for(register int j = h[i]; j != -1; j = ne[j]) {
  70. int x = e[j];
  71. if(f[x]+a[i] > f[i]) fa[i] = x, f[i] = f[x] + a[i];
  72. }
  73. if(f[i] > f[mx]) mx = i;
  74. }
  75. dfs(fa[mx]);
  76. IO::write(mx);
  77. puts("");
  78. IO::write(f[mx]);
  79. return 0;
  80. }