AtCoder Grand Contest 011

Submission #1586025

Source codeソースコード

#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,m,I,P,Q;
int cnt,head[100010],to[400010],next[400010],linker[100010];
bool f,vis[100010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	next[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=next[i])
	{
		int y=to[i];
		if (y!=fa)
		{
			if (vis[y])
			{
				if (linker[x]==linker[y])
				{
					f=true;
				}
				continue;
			}
			else
			{
				dfs(y,x);
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	int x,y;
	for (int i=0;i<m;i++)
	{
		scanf("%d%d",&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ユーザ名 Emma194
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 CE
Score得点 -
Source lengthソースコード長 1969 Byte
File nameファイル名
Exec time実行時間 -
Memory usageメモリ使用量 -

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

./Main.cpp: In function ‘void add(int, int)’:
./Main.cpp:64:2: error: reference to ‘next’ is ambiguous
next[cnt]=head[x];
^
./Main.cpp:58:33: note: candidates are: int next [400010]
int cnt,head[100010],to[400010],next[400010],linker[100010];
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:66:0,
from /usr/include/c++/5/algorithm:61,
from ./Main.cpp:4:
/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 ‘void dfs(int, int)’:
./Main.cpp:71:25: error: reference to ‘next’ is ambiguous
for (int i=head[x];i;i=next[i])
^
./Main.cpp:58:33: note: candidates are: int next [400010]
int cnt,head[100010],to[400010],next[400010],linker[100010];
^...

Test case