QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#180259#2169. 'S No ProblemAlleks_BWA 1ms6040kbC++14624b2023-09-15 17:21:172023-09-15 17:21:17

Judging History

你现在查看的是最新测评结果

  • [2023-09-15 17:21:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6040kb
  • [2023-09-15 17:21:17]
  • 提交

answer

#include <bits/stdc++.h>
#define L 100005
using namespace std;

int n;
vector <pair <int, int>> G[L];
int root = 1, pathLength, maxPath;
bool vis[L];

void DFS(int node) {
  vis[node] = true;
  maxPath = max(maxPath, pathLength);
  for (auto it : G[node]) {
    if (!vis[it.first]) {
      pathLength += it.second;
      DFS(it.first);
      pathLength -= it.second;
    }
  }
}

int main(){
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  DFS(root);
  cout << maxPath << "\n";
  return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6040kb

input:

5
1 2 1
1 3 2
1 4 3
1 5 4

output:

4

result:

wrong answer 1st lines differ - expected: '10', found: '4'