示例#1
0
    public static void Solve()
    {
        var n  = I;
        var m  = I;
        var l  = new int[m];
        var r  = new int[m];
        var d  = new long[m];
        var gr = new AdjacencyList <long>(n);

        Repeat(m, i =>
        {
            l[i] = I - 1;
            r[i] = I - 1;
            d[i] = L;
            gr.Add(l[i], r[i], d[i]);
            gr.Add(r[i], l[i], -d[i]);
        });

        var x = new long[n];

        foreach (var edge in gr.DepthFirstSearch())
        {
            x[edge.Target] = x[edge.Source] + edge.Cost;
        }

        Repeat(m, j => { if (x[r[j]] - x[l[j]] != d[j])
                         {
                             Answer(No);
                         }
               });
        Answer(Yes);
    }