/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 584.0 KiB
#3 Accepted 1ms 580.0 KiB
#4 Accepted 2ms 488.0 KiB
#5 Wrong Answer 10ms 496.0 KiB
#6 Wrong Answer 10ms 576.0 KiB

Code

#include <bits/stdc++.h>

using namespace std;

const int mxN = 1003;
vector<vector<int>> g(mxN);
string s;
int res;

bool ispal(string t) {
  for (int i = 0, j = t.size() - 1; j > i; i++, j--)
    if (t[i] != t[j])
      return false;
  return true;
}

void dfs(int node, int par, string path) {
  path += s[node];
  if (ispal(path))
    res = max(res, (int)path.size());
  for (auto &next_node : g[node]) {
    if (next_node != par) {
      dfs(next_node, node, path);
    }
  }
  path.pop_back();
}

void solve() {
  int n, q;
  cin >> n >> s;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cin >> q;
  while (q--) {
    int x;
    char c;
    cin >> x >> c;
    if (c != s[x - 1]) {
      s[x - 1] = c;
      string t;
      res = 0;
      dfs(0, -1, t);
    }
    cout << res << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1045 Largest palindrome in tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-11 13:43:42
Judged At
2024-11-11 03:27:23
Judged By
Score
15
Total Time
10ms
Peak Memory
584.0 KiB