結果

問題 No.1605 Matrix Shape
ユーザー publflpublfl
提出日時 2021-07-16 22:13:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,132 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 49,868 KB
実行使用メモリ 23,272 KB
最終ジャッジ日時 2023-09-20 14:20:33
合計ジャッジ時間 3,597 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,624 KB
testcase_01 AC 4 ms
7,748 KB
testcase_02 AC 3 ms
7,592 KB
testcase_03 AC 4 ms
7,684 KB
testcase_04 AC 3 ms
7,532 KB
testcase_05 AC 4 ms
7,704 KB
testcase_06 AC 4 ms
7,680 KB
testcase_07 AC 3 ms
7,592 KB
testcase_08 AC 5 ms
7,688 KB
testcase_09 AC 5 ms
7,588 KB
testcase_10 AC 4 ms
7,608 KB
testcase_11 WA -
testcase_12 AC 4 ms
7,732 KB
testcase_13 AC 4 ms
7,548 KB
testcase_14 AC 4 ms
7,560 KB
testcase_15 AC 4 ms
7,652 KB
testcase_16 AC 4 ms
7,560 KB
testcase_17 AC 3 ms
7,668 KB
testcase_18 AC 4 ms
7,652 KB
testcase_19 AC 143 ms
23,272 KB
testcase_20 AC 94 ms
15,548 KB
testcase_21 AC 94 ms
15,488 KB
testcase_22 AC 116 ms
19,720 KB
testcase_23 AC 134 ms
21,884 KB
testcase_24 AC 135 ms
20,140 KB
testcase_25 AC 37 ms
8,720 KB
testcase_26 AC 38 ms
8,708 KB
testcase_27 AC 39 ms
8,708 KB
testcase_28 AC 38 ms
8,632 KB
testcase_29 AC 38 ms
8,644 KB
testcase_30 AC 81 ms
12,464 KB
testcase_31 AC 77 ms
12,436 KB
testcase_32 AC 68 ms
11,600 KB
testcase_33 AC 63 ms
10,464 KB
testcase_34 AC 41 ms
8,324 KB
testcase_35 AC 71 ms
14,500 KB
testcase_36 AC 50 ms
15,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:61:21: 警告: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
   61 |                 int p,q;
      |                     ^

ソースコード

diff #

#include <stdio.h>
#include <vector>

int check[200010],check2[200010];
std::vector<int> V[200010];

void func(int k)
{
	if(check2[k]) return;
	check2[k] = 1;
	for(int i=0;i<V[k].size();i++) func(V[k][i]);
}

int in[200010],out[200010];

int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++)
	{
		int b,c;
		scanf("%d%d",&b,&c);
		check[b] = check[c] = 1;
		V[b].push_back(c);
		out[b]++, in[c]++;
	}
	
	int s1 = 0, s2 = 0;
	for(int i=1;i<=200000;i++)
	{
		if(out[i]-in[i]==1) s1++;
		if(in[i]-out[i]==1) s2++;
	}
	
	if(s1==0&&s2==0)
	{
		for(int i=1;i<=200000;i++)
		{
			if(check[i]==1)
			{
				func(i);
				break;
			}
		}
		for(int i=1;i<=200000;i++)
		{
			if(check[i]==1&&check2[i]==0)
			{
				printf("0");
				return 0;
			}
		}
		
		int ans = 0;
		for(int i=1;i<=200000;i++) if(check[i]==1) ans++;
		printf("%d",ans);
	}
	else if(s1==1&&s2==1)
	{
		int p,q;
		for(int i=1;i<=200000;i++)
		{
			if(out[i]-in[i]==1) p = i;
			if(in[i]-out[i]==1) q = i;
		}
		func(p);
		for(int i=1;i<=200000;i++)
		{
			if(check[i]==1&&check2[i]==0)
			{
				printf("0");
				return 0;
			}
		}
		printf("1");
	}
	else printf("0");
}
0