QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#179930#7249. Jimi Hendrixmendicillin2#WA 2ms9684kbC++171.8kb2023-09-15 13:40:412023-09-15 13:40:41

Judging History

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

  • [2023-09-15 13:40:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9684kb
  • [2023-09-15 13:40:41]
  • 提交

answer

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

template <class T> int sz(T&& a) { return int(size(forward<T>(a))); }

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using ll = int64_t;
using vi = vc<int>;

template <class F>
struct ycr {
	F f;
	
	template <class T>
	explicit ycr(T&& f_) : f(forward<T>(f_)) {}

	template <class... Args>
	decltype(auto) operator()(Args&&... args) {
		return f(ref(*this), forward<Args>(args)...);
	}
};
template <class F>
decltype(auto) yc(F&& f) {
	return ycr<decay_t<F>>(forward<F>(f));
}

const int N=5e5+5;
int n,m;
char c[N];
struct node{
	int to,last;
	char ch;
}tree[N*2];
int ss=1,head[N];
inline void add(int from,int to,char ch)
{
	tree[++ss].to=to;
	tree[ss].ch=ch;
	tree[ss].last=head[from];
	head[from]=ss;
}
int f1[N],f2[N];
int p1[N],p2[N];
inline void dfs(int from,int x)
{
	//cout<<from<<" "<<x<<" "<<"yes"<<endl;
	p1[x]=p2[x]=x;
	for(int i=head[x];i;i=tree[i].last)
	{
		int k=tree[i].to;
		if(k==from) continue;
		dfs(x,k);
		if(f1[x]+1>=f2[k])
		{
			cout<<p1[x]<<" "<<p2[k]<<"\n";
			exit(0);
		}
		if(f1[k]+1>=f2[x])
		{
			cout<<p1[k]<<" "<<p2[x]<<"\n";
			exit(0);
		}
		if(f1[k]+(tree[i].ch==c[f1[k]+1])>f1[x])
		{
			f1[x]=f1[k]+(tree[i].ch==c[f1[k]+1]);
			p1[x]=p1[k];
		}
		if(f2[k]-(tree[i].ch==c[f2[k]-1])<f2[x])
		{
			f2[x]=f2[k]-(tree[i].ch==c[f2[k]-1]);
			p2[x]=p2[k];
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	cout << fixed << setprecision(20);
	cin>>n>>m;
	for(int i=1;i<=n;i++) f2[i]=m+1;
	int u,v;
	char ch;
	for(int i=1;i<=n-1;i++) 
	{
		cin>>u>>v>>ch;
		add(u,v,ch); add(v,u,ch);
	}
	cin>>(c+1);
	c[0]=c[n+1]='+';
	dfs(0,1);
	//for(int i=1;i<=n;i++) cout<<f1[i]<<" "<<f2[i]<<endl;
	cout<<"-1 -1"<<"\n";
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9684kb

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:

3 9

result:

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

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 9616kb

input:

2 1
1 2 b
b

output:

-1 -1

result:

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