本文整理汇总了C#中Edge.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# Edge.OrderBy方法的具体用法?C# Edge.OrderBy怎么用?C# Edge.OrderBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Edge
的用法示例。
在下文中一共展示了Edge.OrderBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
{
int n = fs.NextInt();
int m = fs.NextInt();
Edge[] edges = new Edge[m];
string[] ans = new string[m];
for (int i = 0; i < m; i++)
{
edges[i] = new Edge { Id = i, Weight = fs.NextInt(), IsInMST = fs.NextInt() == 1 };
}
edges = edges.OrderBy(e => e.Weight).ThenByDescending(e => e.IsInMST).ToArray();
long inMst = 0;
long notInMst = 0;
List<EdgeOcc> edgeOccs = new List<EdgeOcc>();
foreach (Edge e in edges)
{
if (e.IsInMST)
{
ans[e.Id] = (inMst + 1) + " " + (inMst + 2);
inMst++;
}
else
{
notInMst++;
if (notInMst > (inMst * (inMst - 1)) / 2)
{
writer.WriteLine(-1);
return;
}
else
{
edgeOccs.Add(new EdgeOcc { VertexCount = inMst + 1, Edge = e });
}
}
}
long p = inMst + 1;
long q = p - 2;
for (int i = edgeOccs.Count - 1; i >= 0; i--)
{
while (edgeOccs[i].VertexCount < p)
{
p--;
q = p - 2;
}
ans[edgeOccs[i].Edge.Id] = q + " " + p;
q--;
if (q <= 0)
{
p--;
q = p - 2;
}
}
for (int i = 0; i < m; i++)
{
writer.WriteLine(ans[i]);
}
}
}