AtCoder Grand Contest 006

Submission #1365714

Source codeソースコード

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=2e5+100;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int head[N],next[N],to[N],w[N];
int c[3],col[N],e;
bool vis[N],flag;
inline void dfs(int k,int d) {
	c[col[k]=d]++;vis[k]=true;
	for (int i=head[k];i;i=next[i],e++)
		if (!vis[to[i]]) dfs(to[i],(d+w[i])%3);
		else if ((d+w[i])%3!=col[to[i]]) flag=false;
}
int main()
{
	int n=gi(),m=gi(),i,a,b,tot=0;LL ans=0;
	for (i=1;i<=m;i++) {
		a=gi(),b=gi();
		to[++tot]=b,next[tot]=head[a],head[a]=tot,w[tot]=1;
		to[++tot]=a,next[tot]=head[b],head[b]=tot,w[tot]=2;
	}
	for (i=1;i<=n;i++)
		if (!vis[i]) {
			c[0]=c[1]=c[2]=e=0;
			flag=true;
			dfs(i,0);
			if (flag)
				if (c[0]&&c[1]&&c[2])
					ans+=1LL*c[0]*c[1]+1LL*c[0]*c[2]+1LL*c[1]*c[2];
				else ans+=e>>1;
			else ans+=1LL*(c[0]+c[1]+c[2])*(c[0]+c[1]+c[2]);
		}
	printf("%lld\n",ans);
	return 0;
}

Submission

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

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

./Main.cpp: In function ‘void dfs(int, int)’:
./Main.cpp:26:25: error: reference to ‘next’ is ambiguous
for (int i=head[k];i;i=next[i],e++)
^
./Main.cpp:21:13: note: candidates are: int next [200100]
int head[N],next[N],to[N],w[N];
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:66:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from ./Main.cpp:1:
/usr/include/c++/5/bits/stl_iterator_base_funcs.h:184:5: note: template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
next(_ForwardIterator __x, typename
^
./Main.cpp: In function ‘int main()’:
./Main.cpp:35:15: error: reference to ‘next’ is ambiguous
to[++tot]=b,next[tot]=head[a],head[a]=tot,w[tot]=1;
...

Test case