QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178086#7249. Jimi HendrixPhantomThreshold#WA 0ms24892kbC++201.1kb2023-09-13 17:53:242023-09-13 17:53:25

Judging History

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

  • [2023-09-13 17:53:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:24892kb
  • [2023-09-13 17:53:24]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
//#define int long long
using namespace std;

const int maxn = 510000;

int n;
vector< pair<int,int> >V[maxn];
int a[maxn],an;

int f[maxn],g[maxn],fa[maxn];
int fi[maxn],gi[maxn];
int ansx,ansy;
void dfs(const int x)
{
	f[x]=0; fi[x]=x;
	g[x]=an+1; gi[x]=x;
	
	for(auto [y,c]:V[x]) if(y!=fa[x])
	{
		fa[y]=x; dfs(y);
		
		if(f[x]+1>=g[y]) ansx=fi[x],ansy=gi[y];
		if(f[y]+1>=g[x]) ansx=fi[y],ansy=gi[x];
		
		int cc=f[y];
		if(cc<an && c==a[cc+1]) cc++;
		if(f[x]<cc) f[x]=cc,fi[x]=fi[y];
		
		cc=g[y];
		if(cc>1 && c==a[cc-1]) cc--;
		if(g[x]>cc) g[x]=cc,gi[x]=gi[y];
	}
}

signed main()
{
	ios_base::sync_with_stdio(false); ////////////////////////////////////////
	cin.tie(0);
	
	cin>>n>>an;
	for(int i=1;i<n;i++)
	{
		int x,y; cin>>x>>y;
		string ss; cin>>ss;
		V[x].emplace_back( y,ss[0]-'a' );
		V[y].emplace_back( x,ss[0]-'a' );
	}
	string str; cin>>str; str=' '+str;
	for(int i=1;i<=an;i++) a[i]=str[i]-'a';
	
	ansx=ansy=-1;
	dfs(1);
	
	cout<<ansx<<' '<<ansy<<endl;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 23844kb

input:

9 3
1 2 a
2 3 b
2 4 a
4 5 b
4 6 c
6 7 d
6 8 a
8 9 b
acb

output:

1 9

result:

ok Both jury and contestant have lovely and correct paths :)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 24892kb

input:

2 1
1 2 b
b

output:

-1 -1

result:

wrong answer contestant could not find a correct path although it exists :(