AtCoder Grand Contest 011

Submission #1587928

Source codeソースコード

#include<cstdio>
int N,M;
struct edge{int to;edge*next;}E[400010],*ne=E,*first[100010];
void link(int u,int v){*ne=(edge){v,first[u]};first[u]=ne++;}
bool vis[100010],col[100010];
int tot;
bool dfs(int i){
	vis[i]=1;++tot;
	bool r=1;
	for(edge*e=first[i];e;e=e->next){
		if(!vis[e->to])col[e->to]=!col[i],r|=dfs(e->to);
		else if(col[e->to]==col[i])r=0;
	}
	return r;
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0,u,v;i<M;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	int a=0,b=0,s=0;
	for(int i=1;i<=N;i++)if(!vis[i]){
		int o=tot;
		if(dfs(i))(o=tot-o)>1?++a:++s;
		else++b;
	}
	long long ans=(2ll*N-s)*s+(a+b)*1ll*(a+b)+1ll*a*a;
	printf("%lld\n",ans);
}

Submission

Task問題 C - Squared Graph
User nameユーザ名 vjudge5
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 659 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&N,&M);
^
./Main.cpp:18:65: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(int i=0,u,v;i<M;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt
All 0 / 800 sample1.txt,sample2.txt,in1.txt,in10.txt,in11.txt,in12.txt,in13.txt,in14.txt,in15.txt,in16.txt,in17.txt,in18.txt,in19.txt,in2.txt,in20.txt,in21.txt,in22.txt,in23.txt,in24.txt,in25.txt,in26.txt,in27.txt,in28.txt,in3.txt,in4.txt,in5.txt,in6.txt,in7.txt,in8.txt,in9.txt,sample1.txt,sample2.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt AC 1 ms 128 KB
in10.txt AC 1 ms 256 KB
in11.txt AC 1 ms 128 KB
in12.txt AC 11 ms 4224 KB
in13.txt AC 11 ms 4224 KB
in14.txt AC 22 ms 6272 KB
in15.txt WA
in16.txt WA
in17.txt WA
in18.txt WA
in19.txt AC 24 ms 7552 KB
in2.txt WA
in20.txt WA
in21.txt AC 47 ms 10112 KB
in22.txt AC 39 ms 6912 KB
in23.txt AC 36 ms 6528 KB
in24.txt AC 2 ms 1152 KB
in25.txt AC 46 ms 10112 KB
in26.txt WA
in27.txt WA
in28.txt AC 47 ms 10112 KB
in3.txt AC 1 ms 128 KB
in4.txt AC 1 ms 128 KB
in5.txt AC 35 ms 6400 KB
in6.txt AC 3 ms 1280 KB
in7.txt AC 3 ms 1408 KB
in8.txt WA
in9.txt AC 15 ms 4864 KB
sample1.txt AC 1 ms 128 KB
sample2.txt AC 1 ms 128 KB