Submission #1365714
Source Code Expand
#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 Info
Submission Time | |
---|---|
Task | F - Blackout |
User | laofu |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1232 Byte |
Status | CE |
Compile Error
./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; ...