#include <bits/stdc++.h>
using namespace std;
string act;
vector<int> adj[50010];
map<string,int> m;
void dfs(int u,int pa,string s){
m[s]++;
//cout << s << "hi\n";
//cout << s << "hi\n";
for (int v: adj[u]){
if (v == pa) continue;
dfs(v,u,s+act[v]);
}
}
int main(){
int n;
cin >> n;
cin >> act;
//cout << act << "read\n";
for (int i = 0; i < n-1; i++){
int a,b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
int ans = 0;
for (int i = 0; i < n; i++){
m.clear();
//cout << act[i] << "\n";
string s = "";
s += act[i];
dfs(i,-1,s);
for (auto it = m.begin(); it != m.end(); ++it){
//cout<< it->first << " " << it->second << "\n";
if (it->second >= 2) ans = max(ans,2*(int)((it->first).length())-1);
}
// cout << "hi\n";
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
530 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2106 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |