結果
| 問題 |
No.479 頂点は要らない
|
| ユーザー |
14番
|
| 提出日時 | 2017-01-28 11:23:26 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 298 ms / 1,500 ms |
| コード長 | 3,046 bytes |
| コンパイル時間 | 1,261 ms |
| コンパイル使用メモリ | 109,824 KB |
| 実行使用メモリ | 57,248 KB |
| 最終ジャッジ日時 | 2024-12-23 20:42:59 |
| 合計ジャッジ時間 | 7,525 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
public class Program
{
public void Proc() {
Reader.IsDebug = false;
int[] inp = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
int pointCount = inp[0];
int roadCount = inp[1];
List<Point> pointList = new List<Point>();
for(int i=0; i<pointCount; i++) {
pointList.Add(new Point(i));
}
Dictionary<int, Dictionary<int, bool>> road = new Dictionary<int, Dictionary<int, bool>>();
for(int i=0; i<roadCount; i++) {
inp = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
if(!road.ContainsKey(inp[0])) {
road.Add(inp[0], new Dictionary<int, bool>());
}
if(!road.ContainsKey(inp[1])) {
road.Add(inp[1], new Dictionary<int, bool>());
}
road[inp[0]].Add(inp[1], false);
road[inp[1]].Add(inp[0], false);
}
StringBuilder ans = new StringBuilder();
for(int i=pointList.Count-1; i>=0; i--) {
bool must = false;
if(pointList[i].mustBuy != null) {
if(pointList[i].mustBuy.Value) {
must = true;
} else {
must = false;
}
} else {
foreach(int key in road[i].Keys) {
if(pointList[key].mustBuy != null && pointList[key].mustBuy.Value == false) {
must = true;
break;
}
}
pointList[i].mustBuy = must;
}
if(must) {
ans.Append(1);
} else {
ans.Append(0);
}
if(!pointList[i].mustBuy.Value) {
foreach(int key in road[i].Keys) {
if(pointList[key].mustBuy == null) {
pointList[key].mustBuy = true;
}
}
}
}
Console.WriteLine(ans.ToString().TrimStart(new char[]{'0'}));
}
private class Point {
public int ID;
public Nullable<Boolean> mustBuy = null;
public Point(int id) {
this.ID = id;
}
}
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
4 5
0 1
0 2
0 3
1 2
2 3
";
public static string ReadLine() {
if(IsDebug) {
if(SReader == null) {
SReader = new System.IO.StringReader(InitText.Trim());
}
return SReader.ReadLine();
} else {
return Console.ReadLine();
}
}
}
public static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
14番