#include "testlib.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)
using namespace std;
using namespace __gnu_pbds;
mt19937_64 gen(time(0));
int func(int x)
{
return gen() % x;
}
typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
//const int mod = 1e9 + 7;
ld score(ll a, ll b)
{
if (a == b)
{
return 10.;
}
return ceil(((ld)a * a) / ((ld)b * b) * 10. * 100) / 100;
}
const int maxn = 1e6 + 66;
const int maxk = 1e6 + 66;
const int maxq = 3e7;
map <int, int> g[maxn];
bool used[maxk];
bool cas[maxk];
int a[maxn], b[maxn], c[maxn];
int castles[maxk];
int n, m, k, t, A, s;
int main(int argc, char * argv[])
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
setName("scored checker");
registerTestlibCmd(argc, argv);
int test_id = inf.readInt();inf.skipBlanks();
n = inf.readInt(1, maxn);inf.skipBlanks();
m = inf.readInt(n-1, 100000000);inf.skipBlanks();
k = inf.readInt(1, n);inf.skipBlanks();
t = inf.readInt();inf.skipBlanks();
A = inf.readInt();inf.skipBlanks();
s = inf.readInt(1, n);inf.skipBlanks();
--s;
for(int i = 0; i < m; ++i)
{
int x, y, w;
x = inf.readInt(1, n);inf.skipBlanks();
y = inf.readInt(1, n);inf.skipBlanks();
w = inf.readInt(0, 1000000000);inf.skipBlanks();
--x;
--y;
g[x][y] = w;
g[y][x] = w;
}
{
//
int uk = 0;
for(int i = 0; i < k; ++i)
{
castles[uk] = inf.readInt();inf.skipBlanks();
a[uk] = inf.readInt();inf.skipBlanks();
b[uk] = inf.readInt();inf.skipBlanks();
c[uk] = inf.readInt();inf.skipBlanks();
--castles[uk];
cas[castles[uk]] = 1;
if (!(a[uk] <= 0 && b[uk] <= 0)) ++uk;
}
k = uk;
}
inf.skipBlanks();
inf.readEof();
int coinsa = ans.readInt();ans.skipBlanks();
ans.readEof();
int coinsp = 0;
int cA = A, ct = t, v = s;
int q = ouf.readInt(0, maxq);
ouf.skipBlanks();
for(int i = 0; i < q; ++i)
{
int type = ouf.readInt(1, 2);
ouf.skipBlanks();
if (type == 2)
{
if (!cas[v])
quitf(_wa, "Попытка захвата поля '%d'", v + 1); else
if (used[v])
quitf(_wa, "Повторный захват замка '%d'", v + 1);
else
{
if (cA < c[v])
quitf(_wa, "Не хватает '%d' воинов до захвата замка '%d'", c[v] - cA, v + 1);
cA += a[v];
coinsp += b[v];
}
used[v] = 1;
}
else
{
int to = ouf.readInt(1, n);
--to;
if (g[v].count(to) == 0) quitf(_wa, "Нет ребра из '%d' в '%d'", v + 1, to + 1);
if (ct + g[v][to] > t) quitf(_wa, "Время вышло на запросе '%d'", i + 1);
ct += g[v][to];
v = to;
}
ouf.skipBlanks();
}
ouf.readEof();
if (coinsa < coinsp)
quitf(_fail, "Авторское решение не является оптимальным");
quitp(score(coinsp, coinsa), "jr='%d' ur='%d'", coinsa, coinsp);
return 0;
}
I2luY2x1ZGUgInRlc3RsaWIuaCIKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CgoKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIHNxcih4KSAoeCkgKiAoeCkKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOwoKbXQxOTkzN182NCBnZW4odGltZSgwKSk7CgppbnQgZnVuYyhpbnQgeCkKewogICAgcmV0dXJuIGdlbigpICUgeDsK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aW5mLnJlYWRJbnQoMSwgbik7aW5mLnNraXBCbGFua3MoKTsKICAgIHQgPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICBBID0gaW5mLnJlYWRJbnQoKTtpbmYuc2tpcEJsYW5rcygpOwogICAgcyA9IGluZi5yZWFkSW50KDEsIG4pO2luZi5za2lwQmxhbmtzKCk7CiAgICAtLXM7CgogICAgZm9yKGludCBpID0gMDsgaSA8IG07ICsraSkKICAgIHsKICAgICAgICBpbnQgeCwgeSwgdzsKICAgICAgICB4ID0gaW5mLnJlYWRJbnQoMSwgbik7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICB5ID0gaW5mLnJlYWRJbnQoMSwgbik7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICB3ID0gaW5mLnJlYWRJbnQoMCwgMTAwMDAwMDAwMCk7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICAtLXg7CiAgICAgICAgLS15OwogICAgICAgIGdbeF1beV0gPSB3OwogICAgICAgIGdbeV1beF0gPSB3OwogICAgfQogICAgewogICAgICAgIC8vCiAgICAgICAgaW50IHVrID0gMDsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgazsgKytpKQogICAgICAgIHsKICAgICAgICAgICAgY2FzdGxlc1t1a10gPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICAgICAgICAgIGFbdWtdID0gaW5mLnJlYWRJbnQoKTtpbmYuc2tpcEJsYW5rcygpOwogICAgICAgICAgICBiW3VrXSA9IGluZi5yZWFkSW50KCk7aW5mLnNraXBCbGFua3MoKTsKICAgICAgICAgICAgY1t1a10gPSBpbmYucmVhZEludCgpO2luZi5za2lwQmxhbmtzKCk7CiAgICAgICAgICAgIC0tY2FzdGxlc1t1a107CiAgICAgICAgICAgIGNhc1tjYXN0bGVzW3VrXV0gPSAxOwogICAgICAgICAgICBpZiAoIShhW3VrXSA8PSAwICYmIGJbdWtdIDw9IDApKSArK3VrOwogICAgICAgIH0KICAgICAgICBrID0gdWs7CiAgICB9CiAgICBpbmYuc2tpcEJsYW5rcygpOwogICAgaW5mLnJlYWRFb2YoKTsKICAgIGludCBjb2luc2EgPSBhbnMucmVhZEludCgpO2Fucy5za2lwQmxhbmtzKCk7CiAgICBhbnMucmVhZEVvZigpOwogICAgaW50IGNvaW5zcCA9IDA7CiAgICBpbnQgY0EgPSBBLCBjdCA9IHQsIHYgPSBzOwogICAgaW50IHEgPSBvdWYucmVhZEludCgwLCBtYXhxKTsKICAgIG91Zi5za2lwQmxhbmtzKCk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgcTsgKytpKQogICAgewogICAgICAgIGludCB0eXBlID0gb3VmLnJlYWRJbnQoMSwgMik7CiAgICAgICAgb3VmLnNraXBCbGFua3MoKTsKICAgICAgICBpZiAodHlwZSA9PSAyKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKCFjYXNbdl0pCiAgICAgICAgICAgICAgICBxdWl0Zihfd2EsICLQn9C+0L/Ri9GC0LrQsCDQt9Cw0YXQstCw0YLQsCDQv9C+0LvRjyAnJWQnIiwgdiArIDEpOyBlbHNlCiAgICAgICAgICAgIGlmICh1c2VkW3ZdKQogICAgICAgICAgICAgICAgcXVpdGYoX3dhLCAi0J/QvtCy0YLQvtGA0L3Ri9C5INC30LDRhdCy0LDRgiDQt9Cw0LzQutCwICclZCciLCB2ICsgMSk7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKGNBIDwgY1t2XSkKICAgICAgICAgICAgICAgICAgICBxdWl0Zihfd2EsICLQndC1INGF0LLQsNGC0LDQtdGCICclZCcg0LLQvtC40L3QvtCyINC00L4g0LfQsNGF0LLQsNGC0LAg0LfQsNC80LrQsCAnJWQnIiwgY1t2XSAtIGNBLCB2ICsgMSk7CiAgICAgICAgICAgICAgICBjQSArPSBhW3ZdOwogICAgICAgICAgICAgICAgY29pbnNwICs9IGJbdl07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZFt2XSA9IDE7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGludCB0byA9IG91Zi5yZWFkSW50KDEsIG4pOwogICAgICAgICAgICAtLXRvOwogICAgICAgICAgICBpZiAoZ1t2XS5jb3VudCh0bykgPT0gMCkgcXVpdGYoX3dhLCAi0J3QtdGCINGA0LXQsdGA0LAg0LjQtyAnJWQnINCyICclZCciLCB2ICsgMSwgdG8gKyAxKTsKICAgICAgICAgICAgaWYgKGN0ICsgZ1t2XVt0b10gPiB0KSAgIHF1aXRmKF93YSwgItCS0YDQtdC80Y8g0LLRi9GI0LvQviDQvdCwINC30LDQv9GA0L7RgdC1ICclZCciLCBpICsgMSk7CiAgICAgICAgICAgIGN0ICs9IGdbdl1bdG9dOwogICAgICAgICAgICB2ID0gdG87CiAgICAgICAgfQogICAgICAgIG91Zi5za2lwQmxhbmtzKCk7CiAgICB9CiAgICBvdWYucmVhZEVvZigpOwogICAgaWYgKGNvaW5zYSA8IGNvaW5zcCkKICAgICAgICBxdWl0ZihfZmFpbCwgItCQ0LLRgtC+0YDRgdC60L7QtSDRgNC10YjQtdC90LjQtSDQvdC1INGP0LLQu9GP0LXRgtGB0Y8g0L7Qv9GC0LjQvNCw0LvRjNC90YvQvCIpOwogICAgcXVpdHAoc2NvcmUoY29pbnNwLCBjb2luc2EpLCAianI9JyVkJyB1cj0nJWQnIiwgY29pbnNhLCBjb2luc3ApOwogICAgcmV0dXJuIDA7Cn0K