理解题意后不难
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int NP, NT, n;
int tokens[110];
char s[1000];
vector<int> from[110];
vector<int> to[110];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q = 0;
while(scanf("%d", &NP) == 1 && NP) {
q++;
memset(tokens, 0, sizeof(tokens));
for(int i = 0; i < 110; i++) {
from[i].clear();
to[i].clear();
}
for(int i = 0; i < NP; i++) scanf("%d", &tokens[i+1]);
scanf("%d", &NT);
for(int i = 0; i < NT; i++) {
int x;
while(scanf("%d", &x) == 1 && x) {
if(x < 0) from[i].push_back(x*(-1));
else to[i].push_back(x);
}
}
scanf("%d", &n);
int cnt &#