namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class UnionFind { (int parent, int size, int edges)[] Verticals { get; set; } public UnionFind(int verticals) { Verticals = new (int, int, int)[verticals]; for (int i = 0; i < verticals; i++) Verticals[i] = (i, 1, 0); } public int Union(int x, int y) { (x, y) = (Find(x), Find(y)); if (Size(x) < Size(y)) (x, y) = (y, x); Verticals[x].edges += 1; if (x == y) return x; Verticals[x].edges += Verticals[y].edges; 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; public int Edges(int x) => Parent(x).edges; (int parent, int size, int edges) 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; } } class AtCoder { object? Solve() { var n = Int(); var k = Int(); var c = Input(); var edges = new (int, int, int, int, bool)[k]; for (var i = 0; i < k; i++) { var u = Int() - 1; var v = Int() - 1; var w = Int(); var p = Int(); edges[i] = (w, p, u, v, false); } Array.Sort(edges); var ans = 0L; var minC = 0L; var uf = new UnionFind(n); var g = n.Repeat(() => new List<(int, int)>()); for (var i = 0; i < k; i++) { var (w, p, u, v, _) = edges[i]; if (uf.Find(u) != uf.Find(v)) { minC += w; uf.Union(u, v); edges[i].Item5 = true; g[u].Add((v, w)); g[v].Add((u, w)); ans = Math.Max(ans, p); } } if (minC > c) return -1; var f = new long[n]; void S(int v, int prev) { foreach (var (next, nw) in g[v]) { if (next == prev) continue; f[next] = Math.Max(f[next], nw); S(next, v); } } S(edges[0].Item3, -1); foreach (var (w, p, u, v, t) in edges) { if (t) continue; var max = Math.Max(f[u], f[v]); if (minC - max + w < c) ans = Math.Max(ans, p); } return ans; } 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(); 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() where T : IParsable => T.Parse(String(), null); int Int() => Input(); 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 }