比赛 EYOI与SBOI开学欢乐赛5th 评测结果 AAWAA
题目名称 SERNET模拟 最终得分 80
用户昵称 HeSn 运行时间 0.006 s
代码语言 C++ 内存使用 3.86 MiB
提交时间 2022-09-16 21:17:37
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n, m, k, a[1010], g[1010][1010], aa[1010], t[1010], nm[1010], st[1010], to[1010], tim, cnt, d[1001];
map<int, int> mp;
vector<int> cd[1010];
bool vis[1010], vis2[1010][10010];
void dfs(int num, int x, int to, int time) {
	if(time > tim) {
		return ;
	}
	for(int i = 0; i < cd[x].size(); i ++) {
		int u = cd[x][i];
		for(int j = time; j < time + g[u][x]; j ++) {
			vis2[num][j] = 1;
		}
		if(u == to || u == x || vis[u]) {
			continue;
		}
		vis[u] = 1;
		dfs(num, u, to, time + g[u][x]);
	}
}
signed main() {
	freopen("sernet.in", "r", stdin);
	freopen("sernet.out", "w", stdout);
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		aa[a[i]] = i;
	}
	cin >> m;
	for(int i = 1; i <= m; i ++) {
		int x, y, z;
		cin >> x >> y >> z;
		x = aa[x];
		y = aa[y];
		cd[x].push_back(y);
		cd[y].push_back(x);
		g[x][y] = g[y][x] = z;
	}
	cin >> k;
	for(int i = 1; i <= k; i ++) {
		cin >> nm[i] >> t[i] >> st[i] >> to[i];
		st[i] = aa[st[i]];
		to[i] = aa[to[i]];
		if(!mp[nm[i]]) {
			mp[nm[i]] = ++ cnt;
		}
		nm[i] = mp[nm[i]];
	}
	cin >> tim;
	for(int i = 1; i <= k; i ++) {
		memset(vis, 0, sizeof(vis));
		vis[st[i]] = 1;
		dfs(nm[i], st[i], to[i], t[i]);
	}
	int ans = 0;
//	for(int i = 1; i <= cnt; i ++) {
//		for(int j = 1; j <= 30; j ++) {
//			cout << vis2[i][j] << ' ';
//		}
//		cout << endl;
//	}
	for(int i = 1; i <= cnt; i ++) {
		ans += vis2[i][tim];
	}
	cout << ans;
    return 0;
}