結果

問題 No.3013 ハチマキ買い星人
ユーザー 鳩でもわかるC#
提出日時 2025-01-26 00:31:12
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 2,136 bytes
コンパイル時間 8,293 ms
コンパイル使用メモリ 171,692 KB
実行使用メモリ 225,856 KB
最終ジャッジ日時 2025-01-26 00:31:42
合計ジャッジ時間 28,374 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14 WA * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (118 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class Edge
{
    public Edge(int f, int n, int c)
    {
        From = f;
        Next = n;
        Cost = c;
    }
    public int From = 0;
    public int Next = 0;
    public int Cost = 0;
}

class Program
{
    static void Main()
    {
        long N, M, P, Y;
        {
            long[] vs = Console.ReadLine().Split().Select(_ => long.Parse(_)).ToArray();
            N = vs[0];
            M = vs[1];
            P = vs[2];
            Y = vs[3];
        }

        List<Edge>[] lists = new List<Edge>[N];
        for (int i = 0; i < N; i++)
            lists[i] = new List<Edge>();

        for (int i = 0; i < M; i++)
        {
            int[] vs = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
            int a = vs[0] - 1;
            int b = vs[1] - 1;
            int c = vs[2];
            lists[a].Add(new Edge(a, b, c));
            lists[b].Add(new Edge(b, a, c));
        }
        long[] costs = new long[N];
        for (int i = 0; i < N; i++)
            costs[i] = long.MaxValue;

        PriorityQueue<int, long> pq = new PriorityQueue<int, long>();
        pq.Enqueue(0, 0);
        while (pq.Count > 0)
        {
            pq.TryDequeue(out int cur, out long cost);
            if (costs[cur] < long.MaxValue)
                continue;

            costs[cur] = cost;

            foreach (Edge edge in lists[cur])
            {
                long ncost = cost + edge.Cost;
                if (ncost >= Y)
                    continue;

                int next = edge.Next;
                if (costs[next] > ncost)
                {
                    costs[next] = ncost;
                    pq.Enqueue(next, ncost);
                }
            }
        }
        long ans = 0;
        for (int i = 0; i < P; i++)
        {
            int[] vs = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray();
            int a = vs[0] - 1;
            int c = vs[1];
            if (Y - costs[a] > 0)
                ans = Math.Max(ans, (Y - costs[a]) / c);
        }
        Console.WriteLine(ans);
    }
}

0