Orange Boy Can You Solve It Out? Ep.20

「考える問題は簡単ですか」

Programming Detect

You are given a directed graph G with N nodes and M edges. Each node has an operation, which could be "def sth" or "use sth".
An array of nodes A is called Exceptional iff:
- for each 1\leq i\leq |A|-1 there is an edge connecting A_i and A_{i+1}
- There exists some string S so that the use operation comes earlier than the first def operation of string S.
For example,def i;use i;def j;use j;def j;use j;use i; meets the second condition.
use i;def i;use i;def i is bad because ths usage of i comes earlier than its declaration.
Your task is to find if the given graph contains an Exceptional path.

example

Input
Graph={1->2,2->3,3->1,2->2}
Operation={"def x","def y","use x"}
Output
NO
Input
Graph={1->2,1->3,2->3}
Operation={"def x","def y","use y"}
Output
YES
Explain
When A=[1,3] "y" is used without declaration.

Constriants

Subtask 1(9.999999999999999999999%): the operation of each node could only be "def var" and "use var"."var" is a constant but not a varible.
Subtask 2(20%): the graph is a directed tree.
Subtask 3(30%): it is made sure that for each i, node i and i+1 are connected.
Subtask 4(20%): the graph is a forest
Subtask 5(20%): N,M<=1000
For all, N,M<=10^5

版权声明:
作者:XGN
链接:https://blog.hellholestudios.top/archives/260
来源:Hell Hole Studios Blog
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>