/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 580.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 1ms 580.0 KiB
#5 Wrong Answer 10ms 428.0 KiB
#6 Wrong Answer 10ms 532.0 KiB
#7 Accepted 2364ms 2.188 MiB
#8 Accepted 2401ms 2.16 MiB
#9 Accepted 2217ms 2.098 MiB
#10 Accepted 2265ms 2.16 MiB
#11 Accepted 1ms 580.0 KiB
#12 Accepted 1ms 532.0 KiB
#13 Accepted 1ms 576.0 KiB
#14 Accepted 16ms 1.938 MiB

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-10-03 13:41:57
Judged By
Score
85
Total Time
2401ms
Peak Memory
2.188 MiB