0pts全wa求调
查看原帖
0pts全wa求调
762199
fulichang楼主2023/11/10 21:10
//from.luogu P3879 by.flic 23-11-10
#include <bits/stdc++.h>

const int N = 500000;
int n, m, cnt = 1;
struct node {
	bool isend;
	int son[26];
	std::vector<int>ans;
} t[N];

void Insert (char *s, int x) {
	int now = 0;
	for (int i = 0; s[i]; i++) {
		int ch = s[i] - 'a';
		if (!t[now].son[ch])
			t[now].son[ch] = cnt++;
		now = t[now].son[ch];
	}
	t[now].ans.push_back(x);
	t[now].isend = true;
}

void Find (char *s) {
	int now = 0;
	for (int i = 0; s[i]; i++) {
		int ch = s[i] - 'a';
		if (!t[now].son[ch]) {
			puts("");
			return;
		}
		now = t[now].son[ch];
	}
	if (!t[now].isend) {
		puts("");
		return;
	}
	for (auto i : t[now].ans)
		printf ("%d ", i);
	puts("");
}

int main (void) {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		int l;
		scanf ("%d", &l);
		for (int j = 1; j <= l; j++) {
			char s[21];
			scanf ("%s", s);
			Insert(s, i);
		}
	}
	scanf ("%d", &m);
	for (int i = 1; i <= m; i++) {
		char s[21];
		scanf ("%s", s);
		Find(s);
	}
	return 0;
}
2023/11/10 21:10
加载中...