結果
| 問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-16 22:36:34 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,840 bytes |
| コンパイル時間 | 8,355 ms |
| コンパイル使用メモリ | 168,344 KB |
| 実行使用メモリ | 281,684 KB |
| 最終ジャッジ日時 | 2024-09-28 21:12:21 |
| 合計ジャッジ時間 | 45,148 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 TLE * 1 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (97 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
namespace AtCoder;
#nullable enable
using System.Numerics;
class UnionFind
{
(int parent, int size)[] Verticals { get; set; }
public UnionFind(int verticals)
{
Verticals = new (int, int)[verticals];
for (int i = 0; i < verticals; i++) Verticals[i] = (i, 1);
}
public int Union(int x, int y)
{
(x, y) = (Find(x), Find(y));
if (Size(x) < Size(y)) (x, y) = (y, x);
if (x == y) return x;
Verticals[x].size += Verticals[y].size;
Verticals[y].parent = x;
return x;
}
public int Find(int x) => Parent(x).parent;
public int Size(int x) => Parent(x).size;
(int parent, int size) Parent(int x)
{
var parentId = Verticals[x].parent;
if (parentId == x) return Verticals[x];
var parent = Parent(parentId);
Verticals[x].parent = parent.parent;
return parent;
}
}
static class Extensions
{
public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
public static int ToFlag(this int i)
{
if (i < 0 || 32 <= i) throw new IndexOutOfRangeException();
return 1 << i;
}
public static bool OfFlag(this int value, int i) => (value & ToFlag(i)) > 0;
public static int WithFlag(this int value, int i, bool f) => f ? (value | ToFlag(i)) : (value & ~ToFlag(i));
}
class AtCoder
{
object? Solve()
{
var n = Int();
var m = Int();
var edges = m.Repeat(() => (Int() - 1, Int() - 1));
var cz = n.Repeat(() => Int() - 1);
var wz = 10.Repeat(Int);
var q = Int();
var ans = new long[q];
var b = 1 << 10;
var ufz = b.Repeat(() => new UnionFind(n));
var csumz = new long[b];
for (var i = 0; i < b; i++)
{
var csum = 0L;
for (var j = 0; j < 10; j++) if (i.OfFlag(j)) csum += wz[j];
csumz[i] = csum;
}
for (var i = 0; i < b; i++)
{
foreach (var (u, v) in edges)
{
if (!i.OfFlag(cz[u]) || !i.OfFlag(cz[v])) continue;
ufz[i].Union(u, v);
}
}
for (var t = 0; t < q; t++)
{
var u = Int() - 1;
var v = Int() - 1;
var minc = long.MaxValue;
for (var i = 0; i < b; i++)
{
if (ufz[i].Find(u) == ufz[i].Find(v)) minc = Math.Min(minc, csumz[i]);
}
if (minc == long.MaxValue) minc = -1;
ans[t] = minc;
}
Out(ans);
return null;
}
public static void Main() => new AtCoder().Run();
public void Run()
{
var res = Solve();
if (res != null)
{
if (res is bool yes) res = yes ? "Yes" : "No";
sw.WriteLine(res);
}
sw.Flush();
}
string[] input = Array.Empty<string>();
int iter = 0;
readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false };
#pragma warning disable IDE0051
string String()
{
while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0);
return input[iter++];
}
T Input<T>() where T : IParsable<T> => T.Parse(String(), null);
int Int() => Input<int>();
void Out(object? x, string? separator = null)
{
separator ??= Environment.NewLine;
if (x is System.Collections.IEnumerable obj and not string)
{
var firstLine = true;
foreach (var item in obj)
{
if (!firstLine) sw.Write(separator);
firstLine = false;
sw.Write(item);
}
}
else sw.Write(x);
sw.WriteLine();
}
#pragma warning restore IDE0051
}