AtCoder Grand Contest 006

Submission #1365230

Source codeソースコード

//by xiqiao
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;
vector <int> v[maxn];
vector <int> g[maxn];
int n,m,flag;
int vis[maxn];
ll ans;
int cnt[4],ge;
int next(int x){if(x==3)return 1;return x+1;}
int next2(int x){if(x==1)return 3;if(x==2)return 1;return 2;}
void dfs(int x,int c){
	cnt[c]++;vis[x]=1;
	for(int i=0;i<(int)v[x].size();i++){
		if(v[x][i]==x)flag=1;
		ge++;
		if(!vis[v[x][i]]){
			dfs(v[x][i],next(c));
		}
	}
	for(int i=0;i<(int)g[x].size();i++){
		ge++;
		if(!vis[g[x][i]]){
			dfs(g[x][i],next2(c));
		}
	}
}
int main(){
//	freopen("table.in","r",stdin);
	//freopen("table.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);g[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			flag=0;cnt[1]=cnt[2]=cnt[3]=0;ge=0;
			dfs(i,1);
			int sum=cnt[0]+cnt[1]+cnt[2];
			if(flag){
				ans+=1ll*sum*sum;
			}
			else if(cnt[3]==0){
				ans+=ge/2;
			}
			else{
				ans+=1ll*cnt[1]*cnt[2];
				ans+=1ll*cnt[2]*cnt[3];
				ans+=1ll*cnt[3]*cnt[1];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Submission

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

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:33: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:35:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int x,y;scanf("%d%d",&x,&y);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
All 0 / 1700 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,1_13.txt,1_14.txt,1_15.txt,1_16.txt,1_17.txt,1_18.txt,1_19.txt,1_20.txt,1_21.txt,1_22.txt,1_23.txt,1_24.txt,1_25.txt,1_26.txt,1_27.txt,1_28.txt,1_29.txt,1_30.txt,1_31.txt,1_32.txt,1_33.txt,1_34.txt,1_35.txt,1_36.txt,1_37.txt,1_38.txt,1_39.txt,1_40.txt,1_41.txt,1_42.txt,1_43.txt,1_44.txt,1_45.txt,1_46.txt,1_47.txt,1_48.txt,1_49.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 3 ms 4992 KB
0_01.txt AC 3 ms 4992 KB
0_02.txt AC 3 ms 4992 KB
1_00.txt AC 3 ms 4992 KB
1_01.txt AC 4 ms 5376 KB
1_02.txt AC 33 ms 11520 KB
1_03.txt AC 37 ms 19328 KB
1_04.txt WA
1_05.txt WA
1_06.txt AC 38 ms 19328 KB
1_07.txt WA
1_08.txt WA
1_09.txt AC 38 ms 19456 KB
1_10.txt WA
1_11.txt AC 38 ms 19328 KB
1_12.txt WA
1_13.txt AC 36 ms 16256 KB
1_14.txt AC 25 ms 8824 KB
1_15.txt AC 26 ms 8824 KB
1_16.txt AC 26 ms 8824 KB
1_17.txt WA
1_18.txt WA
1_19.txt WA
1_20.txt WA
1_21.txt WA
1_22.txt WA
1_23.txt WA
1_24.txt WA
1_25.txt WA
1_26.txt WA
1_27.txt WA
1_28.txt WA
1_29.txt WA
1_30.txt WA
1_31.txt WA
1_32.txt WA
1_33.txt WA
1_34.txt WA
1_35.txt WA
1_36.txt WA
1_37.txt WA
1_38.txt WA
1_39.txt WA
1_40.txt WA
1_41.txt WA
1_42.txt WA
1_43.txt WA
1_44.txt WA
1_45.txt WA
1_46.txt WA
1_47.txt WA
1_48.txt WA
1_49.txt WA