結果
| 問題 |
No.2914 正閉路検出
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-04 22:24:37 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,113 bytes |
| コンパイル時間 | 9,767 ms |
| コンパイル使用メモリ | 165,740 KB |
| 実行使用メモリ | 220,600 KB |
| 最終ジャッジ日時 | 2024-10-04 22:24:59 |
| 合計ジャッジ時間 | 19,933 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 38 WA * 17 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (87 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;
static class Extensions
{
public static T[] Repeat<T>(this int time, Func<T> F) => Enumerable.Range(0, time).Select(_ => F()).ToArray();
}
class AtCoder
{
object? Solve()
{
var n = Int();
var m = Int();
var adjz = n.Repeat(() => new List<(int, int, int)>());
for (var i = 0; i < m; i++)
{
var u = Int() - 1;
var v = Int() - 1;
var w = Int();
adjz[u].Add((v, w, i + 1));
adjz[v].Add((u, -w, i + 1));
}
var dz = new int[n];
var last = n.Repeat(() => -1);
var lj = n.Repeat(() => -1);
var ans = new List<int>();
void S(int v, int prev)
{
if (ans.Count > 0) return;
foreach (var (next, w, j) in adjz[v]) if (j != prev)
{
var nd = dz[v] + w;
if (last[next] != -1)
{
if (dz[next] != nd && ans.Count == 0)
{
var k = v;
ans.Add(j);
while (k != next && k >= 0)
{
ans.Add(lj[k]);
k = last[k];
}
if (dz[next] < nd) ans.Reverse();
Out(ans.Count);
Out(next + 1);
Out(ans, " ");
}
return;
}
dz[next] = nd;
last[next] = v;
lj[next] = j;
S(next, j);
}
}
for (var start = 0; start < n; start++)
{
if (last[start] != -1) continue;
dz[start] = 0;
last[start] = -2;
S(start, -1);
}
if (ans.Count == 0) return -1;
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 };
string String()
{
while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Trim().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();
}
}