diff --git a/.md b/.md new file mode 100644 index 00000000..e23e638b --- /dev/null +++ b/.md @@ -0,0 +1,94 @@ + +# Adversarial Temporal Graph with Stateful Encoding + +Problem Statement +You are given: +A directed graph with n nodes (0 → n-1) +Each edge has: +cost (energy consumption) +time (time taken) +label (a lowercase character 'a'–'z') +An integer K (max energy) +An integer T (max time) +An integer M (modulo) +A forbidden pattern string P + +Rules + +You start at node 0 and want to reach node n-1. + +You maintain: + +1. ⏱ Time +Total time ≤ T + +3. ⚡ Energy +Total energy ≤ K + +4. 🔐 Stateful Encoding +Each path generates a value as follows. +Let χ(c) be the integer value of a label character c, defined by χ('a') = 1, χ('b') = 2, …, χ('z') = 26. +For a path whose edge labels form the string c₁c₂…c_L (each cᵢ ∈ {'a', …, 'z'}), define: + value₀ = 0 + valueᵢ = (valueᵢ₋₁ · 131 + χ(cᵢ)) mod M for i = 1…L +The encoded value of the path is value_L. + +5. 🚫 Forbidden Pattern Constraint +The concatenated labels along your path must NOT contain P as a substring. + +5. 🔁 Temporal Edge Activation +Each edge (u → v) is only usable at certain times: +You are given for each edge: +A list of active intervals [l, r] + +Waiting at nodes: +- You may wait at any node for any non-negative amount of time. +- Waiting increases the current time but does not consume energy and does not traverse any edge. + +Edge usage condition: +- Suppose an edge e has traversal time te and active intervals [l, r]. +- You may start traversing e from time τ only if the entire interval [τ, τ + te] is contained in at least one active interval [l, r] for e. +- Equivalently, τ and τ + te must satisfy l ≤ τ and τ + te ≤ r for some [l, r] of that edge. +7. 🎭 Adversarial Twist (well-defined minimax model) +The game proceeds in discrete moves. A move happens whenever you are at some node u at current time t, with remaining energy and current encoded value. +On each such move, the order of actions is: +1. The adversary may choose at most one outgoing edge e = (u → v) whose label has never been flipped before and permanently change its label to any lowercase character 'a'–'z'. +2. You observe all current labels on outgoing edges of u (including any just flipped by the adversary) and then choose one outgoing edge to traverse, subject to the time, energy, temporal activation, and forbidden-pattern constraints. You may also choose to stop. +3. You traverse the chosen edge, advance time by its time cost, decrease energy by its energy cost, and update the encoded value using the (possibly flipped) label on that edge. +Label flips are persistent: once an edge’s label is changed, all future traversals of that edge see the new label. The adversary cannot change labels of edges that are not outgoing from your current node on that move, and cannot flip the same edge more than once in the entire run. +You must assume the adversary acts to minimize your final value. +You still try to maximize the final value. + +Objective +Return the maximum possible encoded value you can guarantee under worst-case adversarial behavior. +If no valid path exists, return -1 + +Constraints +1 ≤ n ≤ 100 +1 ≤ edges ≤ 500 +1 ≤ K ≤ 5000 +1 ≤ T ≤ 5000 +|P| ≤ 50 +Active intervals per edge ≤ 10 + +Example 1: +n = 3 +edges: +0 → 1 (cost=2, time=2, label='a', active=[0,10]) +1 → 2 (cost=2, time=2, label='b', active=[0,10]) + +K = 5 +T = 5 +M = 1000 +P = "ab" + +Example 2: +n = 3 +edges: +0 → 1 (cost=1, time=1, label='a', active=[0,10]) +1 → 2 (cost=1, time=1, label='c', active=[0,10]) + +K = 5 +T = 5 +M = 1000 +P = "ab"