AtCoder Grand Contest 011

Submission #1588983

Source codeソースコード

#include<bits/stdc++.h>
#define MAXN 1000000+10 
using namespace std;
int n,m,I,P,Q;
int tot,head[MAXN],to[MAXN],nxt[MAXN],linker[MAXN];
bool f,vis[MAXN];
void add(int x,int y){
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa){
	vis[x]=true;
	linker[x]=linker[fa]^1;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y!=fa){
			if(vis[y])
				if(linker[x]==linker[y])f=true;
			else dfs(y,x);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	int x,y;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			if(!head[i]){
				I++;
				vis[i]=true;
				continue;
			}
			f=false;
			dfs(i,0);
			if(f)P++;
			else Q++;
		}
	long long ans=2LL*I*n-1LL*I*I+1LL*P*P+2LL*P*Q+2LL*Q*Q;
	printf("%lld\n",ans);
    return 0;
}

Submission

Task問題 C - Squared Graph
User nameユーザ名 vjudge2
Created time投稿日時
Language言語 Bash (GNU bash v4.3.11)
Status状態 RE
Score得点 0
Source lengthソースコード長 789 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

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 RE
in10.txt RE
in11.txt RE
in12.txt RE
in13.txt RE
in14.txt RE
in15.txt RE
in16.txt RE
in17.txt RE
in18.txt RE
in19.txt RE
in2.txt RE
in20.txt RE
in21.txt RE
in22.txt RE
in23.txt RE
in24.txt RE
in25.txt RE
in26.txt RE
in27.txt RE
in28.txt RE
in3.txt RE
in4.txt RE
in5.txt RE
in6.txt RE
in7.txt RE
in8.txt RE
in9.txt RE
sample1.txt RE
sample2.txt RE