QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86428 | #5034. >.< | Maraschino | 0 | 235ms | 399068kb | C++20 | 3.4kb | 2023-03-09 21:07:19 | 2023-03-09 21:07:22 |
Judging History
answer
#include <bits/stdc++.h>
using PII = std::pair<int, int>;
#define ep emplace
#define eb emplace_back
FILE *fin, *fout, *ferr;
static const int N = 500'005, M = 6'000'005;
int n, m, k, tot, cnt;
int rt[N], ban[N], fail[N], count[N];
std::map<int, int> ch[M], dis[N];
struct TrieNode
{
int ls, rs, val;
TrieNode(int ls = 0, int rs = 0, int val = 0) : ls(ls), rs(rs), val(val) {}
} tr[M];
std::vector<PII> e[N];
struct Node
{
int dis, trie, graph;
Node(int dis = 0, int trie = 0, int graph = 0) : dis(dis), trie(trie), graph(graph) {}
// bool operator<(const Node &a) { return dis > a.dis; }
friend bool operator<(const Node &a, const Node &b) { return a.dis > b.dis; }
};
void insert(int &x, int l, int r, int p, int v)
{
tr[++tot] = tr[x];
x = tot;
if (l == r)
return tr[x].val = v, void();
int mid = (l + r) >> 1;
p <= mid ? insert(tr[x].ls, l, mid, p, v) : insert(tr[x].rs, mid + 1, r, p, v);
}
int query(int x, int l, int r, int p)
{
if (!x)
return 0;
if (l == r)
return tr[x].val;
int mid = (l + r) >> 1;
return p <= mid ? query(tr[x].ls, l, mid, p) : query(tr[x].rs, mid + 1, r, p);
}
signed main()
{
fin = stdin, fout = stdout, ferr = stderr;
// fin = fopen("Input.txt", "r"), fout = fopen("Output.txt", "w+"), ferr = fopen("Debug.txt", "w+");
fscanf(fin, "%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; ++i)
{
static int u, v, w;
fscanf(fin, "%d%d%d", &u, &v, &w);
e[u].eb(v, w), e[v].eb(u, w);
}
for (int i = 1; i <= k; ++i)
{
static int len;
fscanf(fin, "%d", &len);
int p = 0;
for (int j = 1; j <= len; ++j)
{
static int x;
fscanf(fin, "%d", &x);
if (!ch[p][x])
ch[p][x] = ++cnt;
p = ch[p][x];
}
ban[p] = true;
}
std::queue<int> q1;
for (auto [GraphId, TrieId] : ch[0])
insert(rt[0], 1, n, GraphId, TrieId), q1.ep(TrieId);
while (q1.size())
{
int TrieId = q1.front();
q1.pop();
rt[TrieId] = rt[fail[TrieId]];
ban[TrieId] |= ban[fail[TrieId]];
for (auto [GraphTo, TrieTo] : ch[TrieId])
{
insert(rt[TrieId], 1, n, GraphTo, TrieTo);
fail[TrieTo] = query(rt[fail[TrieId]], 1, n, GraphTo);
q1.ep(TrieTo);
}
}
if (ban[ch[0][1]])
return fputs("-1", fout), 0;
std::priority_queue<Node> q2;
q2.ep(dis[1][ch[0][1]] = 0, 1, ch[0][1]);
while (q2.size())
{
auto [Distance, GraphId, TrieId] = q2.top();
q2.pop();
if (count[GraphId] > 20 || dis[GraphId][TrieId] != Distance)
continue;
if (GraphId == n)
return fprintf(fout, "%d\n", Distance), 0;
++count[GraphId];
for (auto [GraphTo, GraphLink] : e[GraphId])
{
int TrieTo = query(rt[TrieId], 1, n, GraphTo);
if (count[GraphTo] > 20 || ban[TrieTo])
continue;
if (!dis[GraphTo].count(TrieTo))
q2.ep(dis[GraphTo][TrieTo] = dis[GraphId][TrieId] + GraphLink, GraphTo, TrieTo);
else if (dis[GraphTo][TrieTo] > dis[GraphId][TrieId] + GraphLink)
q2.ep(dis[GraphTo][TrieTo] = dis[GraphId][TrieId] + GraphLink, GraphTo, TrieTo);
}
}
return fputs("-1\n", fout), 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 75ms
memory: 390360kb
input:
35 100 0 34 7 447733879 24 20 187005344 14 34 654502303 2 31 865194349 20 33 9517055 33 15 991889891 24 33 395599993 13 16 237525328 9 5 373850826 30 34 391470240 10 7 650077565 26 10 400825980 34 27 189924713 19 27 907609573 20 10 614945312 10 5 960007605 1 7 984076202 32 25 539699728 24 31 2553027...
output:
763295759
result:
wrong answer 1st lines differ - expected: '1970522617', found: '763295759'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 235ms
memory: 399068kb
input:
50000 200000 1 7542 37166 116613326 3581 43961 629220971 12873 42953 440313807 31744 5286 697832848 25882 12748 106667302 34760 29676 181570340 41570 9240 885513989 22227 35688 63657981 43180 29194 174058940 8977 41899 48262624 7465 18291 600002514 46925 9281 951474878 2115 31162 373758881 5386 3798...
output:
-915794106
result:
wrong answer 1st lines differ - expected: '2526392504', found: '-915794106'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%