예제 #1
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/bipartitematching
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int l  = cr;
            int r  = cr;
            int m  = cr;
            var mf = new MfGraphInt(l + r + 2);

            for (int i = 0; i < m; i++)
            {
                int a = cr;
                int b = cr;
                mf.AddEdge(a, l + b, 1);
            }
            for (int i = 0; i < l; i++)
            {
                mf.AddEdge(l + r, i, 1);
            }
            for (int i = 0; i < r; i++)
            {
                mf.AddEdge(l + i, l + r + 1, 1);
            }
            cw.WriteLine(mf.Flow(l + r, l + r + 1));
            foreach (var e in mf.Edges())
            {
                int ll = e.From;
                int rr = e.To;
                if (e.Flow == 1 && ll < l && rr < l + r)
                {
                    cw.WriteLineJoin(e.From, e.To - l);
                }
            }
        }
예제 #2
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/convolution_mod
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int n = cr;
            int m = cr;

            int[] a = cr.Repeat(n);
            int[] b = cr.Repeat(m);
            cw.WriteLineJoin(MathLib.Convolution <Mod998244353>(a, b));
        }
예제 #3
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/two_sat
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            _ = cr.Ascii();
            _ = cr.Ascii();
            int n      = cr;
            int m      = cr;
            var twoSat = new TwoSat(n);

            for (int i = 0; i < m; i++)
            {
                int a = cr;
                int b = cr;
                _ = cr.Int();

                int  a1 = Math.Abs(a) - 1;
                bool a2 = a >= 0;
                int  b1 = Math.Abs(b) - 1;
                bool b2 = b >= 0;
                twoSat.AddClause(a1, a2, b1, b2);
            }
            if (twoSat.Satisfiable())
            {
                cw.WriteLine("s SATISFIABLE");
                cw.Write("v ");
                var res    = new int[n + 1];
                var answer = twoSat.Answer();
                for (int i = 0; i < n; i++)
                {
                    if (answer[i])
                    {
                        res[i] = i + 1;
                    }
                    else
                    {
                        res[i] = -(i + 1);
                    }
                }
                cw.WriteLineJoin(res);
            }
            else
            {
                cw.WriteLine("s UNSATISFIABLE");
            }
        }
예제 #4
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/scc
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            int n = cr;
            int m = cr;

            var g = new SccGraph(n);

            for (int i = 0; i < m; i++)
            {
                int u = cr;
                int v = cr;
                g.AddEdge(u, v);
            }

            var scc = g.SCC();

            cw.WriteLine(scc.Length);
            foreach (var v in scc)
            {
                cw.Write(v.Length);
                cw.Write(' ');
                cw.WriteLineJoin(v);
            }
        }
예제 #5
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/zalgorithm
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            string s = cr;

            cw.WriteLineJoin(StringLib.ZAlgorithm(s));
        }
예제 #6
0
        // verification-helper: PROBLEM https://judge.yosupo.jp/problem/suffixarray
        static void Solve(ConsoleReader cr, Utf8ConsoleWriter cw)
        {
            string s = cr;

            cw.WriteLineJoin(StringLib.SuffixArray(s));
        }