比赛 20241127 评测结果 AAAAAAAAAA
题目名称 魔法药水 最终得分 100
用户昵称 darkMoon 运行时间 0.275 s
代码语言 C++ 内存使用 18.98 MiB
提交时间 2024-11-27 09:26:06
显示代码纯文本
  1. #include<bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define mp make_pair
  5. #define int long long
  6. using namespace std;
  7. auto IN = freopen("msyrup.in", "r", stdin);
  8. auto OUT = freopen("msyrup.out", "w", stdout);
  9. auto mread = [](){int x;scanf("%lld", &x);return x;};
  10. const int N = 1005;
  11. int n = mread(), f[N], s[N], to[N][N], e[N], la[N][N];
  12. signed main(){
  13. memset(la, 0x3f ,sizeof(la));
  14. memset(to, -1, sizeof(to));
  15. for(int i = 0; i < n; i ++){
  16. cin >> f[i];
  17. s[i] = 1;
  18. }
  19. {
  20. int a, b, c;
  21. while(cin >> a >> b >> c){
  22. to[a][b] = to[b][a] = c;
  23. }
  24. }
  25. priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
  26. for(int i = 0; i < n; i ++){
  27. q.push(mp(f[i], i));
  28. }
  29. while(q.size()){
  30. int x = q.top().se;
  31. q.pop();
  32. if(e[x]){
  33. continue;
  34. }
  35. e[x] = 1;
  36. for(int y = 0; y < n; y ++){
  37. int z = to[x][y];
  38. if(z != -1){
  39. if(f[x] + f[y] < f[z]){
  40. f[z] = f[x] + f[y];
  41. s[z] = 0;
  42. q.push(mp(f[z], z));
  43. }
  44. }
  45. }
  46. }
  47. for(int i = 0; i < n; i ++){
  48. q.push(mp(f[i], i));
  49. }
  50. memset(e, 0, sizeof(e));
  51. while(q.size()){
  52. int x = q.top().se;
  53. q.pop();
  54. if(e[x]){
  55. continue;
  56. }
  57. e[x] = 1;
  58. for(int y = 0; y < n; y ++){
  59. if(f[y] < f[x] || (f[x] == f[y] && y <= x)){
  60. int z = to[x][y];
  61. if(z != -1){
  62. if(f[x] + f[y] == f[z]){
  63. s[z] += s[x] * s[y];
  64. }
  65. }
  66. }
  67. }
  68. }
  69. printf("%lld %lld", f[0], s[0]);
  70. return 0;
  71. }