R
R
Roman Sippel2017-12-24 16:38:59
C++ / C#
Roman Sippel, 2017-12-24 16:38:59

How to use tags in PUG mixin when it is declared?

Hello!
Please help if you can.
There is a repeating part in the layout of the project. The layout is rendered in pug and I want to use the mixin.
Everything works, but there is a detail - part of the text needs hyphenation - tags <br>.
How to insert them when declaring a mixin?
For example, a simple mixin:

mixin goods-block(title)
  .goods-block
    h4= title

We announce:
+goods-block("Первая часть заголовка" + "<br>" + "Вторая часть")

(as I have not tried, this option is at least compiled and displayed)
I did not find an answer in the Pug documentation how to declare it. Tried in different ways.
The option above displays <br>as text.
hrq32n

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Mercury13, 2019-10-26
@Proshka17

What you did not understand in the solution: you optimize the "black" half of the graph, forgetting that the smallest edge can be in the "white" one.
FOR EACH VERTEX: pointer to “chief” + inversion flag. If the vertex does not have a head, then it points to null.
A DIRECTOR is a vertex that has no bosses. We also assume that the director's inversion flag is always false.
Let's get the getInfoNonDestructive function, it returns a structure of two elements. First, it's the director (never null!!). Secondly, this is the color - XOR of the inversion flags from the top itself to the director.
The getInfo function will call getInfoNonDestructive and then OPTIMIZE THE STRUCTURE: IF the node has a leader THEN: node's head := director, node's inversion flag := node's color.
The merger of companies happens like this. The director of the firm becomes subordinate to one of the members of another firm.
INITIALLY for all vertices, the head is null, the inversion flag is false. That is, each vertex is white and its own director.
SOLUTION: Sort the edges in ascending order.
For each edge…
• Find information about the vertices — the ends of the edge.
• If the director is the same and the colors are different, we do nothing.
• If there is only one director and one color, output the weight of this edge as an answer.
• If the directors are different, we merge the firms. Twisting the inversion flag of the director that has disappeared, so that the colors of the vertices - ends of the edge are different. Even so.

VertexInfo info1 = getInfo(vertex1);
VertexInfo info2 = getInfo(vertex2);
if (…) {
  info1.director->superior = info2.director;
  VertexInfo info1new = getInfoNonDestructive(vertex1);
  if (info1new.color == info2.color)
    info1.director->inverseFlag = !info1.director->inverseFlag;
}

ATTENTION, without optimization of the structure, the complexity from "a little more than O (N)" turns into N²! But specifically in this place, it is important to get information without destruction - it is temporarily forbidden to take anyone out from under the old director until we set the color inversion flag for him.
If there are no edges left, we have a bipartite graph in front of us, this does not happen by condition.
(such a data structure, only without the inversion flag, is called a "disjoint set system").
THEORY. Starting from the "smallest" edges, we begin to paint the vertices in different colors. If at some point this failed (the colors are already the same), we output this edge as the answer. If two colored “islands” (in our terminology “firms”) are connected, one of the islands may have to be inverted, and it is necessary to adjust the inversion so that it does not capture the entire island (judging by the number 10 5 , we are expected to have complexity N log N , not N²). Since connecting pieces of a graph with edges and counting connected components is a real system of disjoint sets, I tried to attach a coloring to this very SPM that does not increase the overall complexity (amortized almost O (1) per transaction).
Try to prove on your own that this system does not depend on the order in which the edges with the same weight are.
And end up on someone else's buoy to enter paradise!

J
jcmvbkbc, 2019-10-15
@jcmvbkbc

I thought that the graph can always be divided into two sets so that the vertices connected by the maximum edge are in one set, and the remaining vertices in the other, that is, the answer will always be the maximum edge. I tested my solution in yandex.contest and got an error on the 8th test. Please tell me what I misunderstood from the condition?
Maybe there is a counterexample?

Counterexample: square, top edge 2, side edges 1, bottom edge 0. In terms of the input to the problem:
4 4
0 1 2
1 2 1
2 3 0
3 0 1

If you break it with your algorithm, then two upper vertices fall into one set, and two lower vertices fall into the second. Then "an edge of minimum weight connecting vertices from the same set" is an edge connecting two lower vertices (2 3), its weight is 0.
But if the graph is divided into two left vertices (3 0) and two right vertices (1 2) , then the "minimum weight edge connecting vertices from the same set" has weight 1, which is better than 0.

L
longclaps, 2019-10-22
@longclaps

You made a mistake here: the maximum edge could be a bridge, and having bitten it, you would break the graph into at least two subgraphs, plus a pair of pershin incident to the edge will be the third subgraph - and this is overkill.
Therefore, just sort through the edges in descending order, which one does not turn out to be a bridge - that will be the solution.

K
Konstantin Kitmanov, 2017-12-24
@SeoHueo

See the documentation section titled Mixin Blocks .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question