Submission #966196
Source Code Expand
#define DEB #include<bits/stdc++.h> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; } template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; } typedef long long int lint; typedef pair<int,int> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } //const int INF=5e8; struct uf{ static const int MAXN=100005; int par[MAXN]; int size[MAXN]; void init(){ memset(par,-1,sizeof(par)); REP(i,MAXN) size[i]=1; } int root(int a){ if(par[a]==-1) return a; return par[a]=root(par[a]); } void unite(int a,int b){ a=root(a);b=root(b); if(a==b) return; if(size[a]<size[b]) swap(a,b); par[b]=a; size[a]+=size[b]; } bool same(int a,int b){ return root(a)==root(b); } }; uf u; int n,m; vector<pi> g[100005]; int col[100005]; bool fail; lint mark[3]; int E; void dfs(int v){ mark[col[v]]++; for(auto e:g[v]){ ++E; if(~col[e.fr] && col[e.fr]!=(col[v]+e.sc)%3) fail=true; if(col[e.fr]==-1){ col[e.fr]=(col[v]+e.sc)%3; dfs(e.fr); } } } int main(){ u.init(); cin>>n>>m; REP(i,m){ int a,b;scanf("%d%d",&a,&b);--a;--b; g[a].pb(mp(b,1)); g[b].pb(mp(a,2)); u.unite(a,b); } memset(col,-1,sizeof(col)); lint res=0; REP(i,n) if(u.root(i)==i){ col[i]=0; CLR(mark); E=0; fail=false; dfs(i); if(fail){ lint s=u.size[i]; res+=s*s; }else if(mark[0] && mark[1] && mark[2]){ res+=mark[0]*mark[1]+mark[1]*mark[2]+mark[2]*mark[0]; }else{ res+=E/2; } } cout<<res<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Blackout |
User | hogloid |
Language | C++14 (GCC 5.4.1) |
Score | 1700 |
Code Size | 2333 Byte |
Status | AC |
Exec Time | 58 ms |
Memory | 11520 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:90:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int a,b;scanf("%d%d",&a,&b);--a;--b; ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1700 / 1700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 6 ms | 3712 KB |
0_01.txt | AC | 6 ms | 3712 KB |
0_02.txt | AC | 6 ms | 3712 KB |
1_00.txt | AC | 6 ms | 3712 KB |
1_01.txt | AC | 7 ms | 3712 KB |
1_02.txt | AC | 37 ms | 6912 KB |
1_03.txt | AC | 42 ms | 11520 KB |
1_04.txt | AC | 42 ms | 11520 KB |
1_05.txt | AC | 42 ms | 11520 KB |
1_06.txt | AC | 43 ms | 11520 KB |
1_07.txt | AC | 42 ms | 11520 KB |
1_08.txt | AC | 43 ms | 11520 KB |
1_09.txt | AC | 43 ms | 11520 KB |
1_10.txt | AC | 42 ms | 11520 KB |
1_11.txt | AC | 42 ms | 11520 KB |
1_12.txt | AC | 42 ms | 11520 KB |
1_13.txt | AC | 42 ms | 11520 KB |
1_14.txt | AC | 33 ms | 7668 KB |
1_15.txt | AC | 33 ms | 7668 KB |
1_16.txt | AC | 33 ms | 7668 KB |
1_17.txt | AC | 26 ms | 6400 KB |
1_18.txt | AC | 52 ms | 8448 KB |
1_19.txt | AC | 55 ms | 8448 KB |
1_20.txt | AC | 56 ms | 8448 KB |
1_21.txt | AC | 58 ms | 8448 KB |
1_22.txt | AC | 52 ms | 8448 KB |
1_23.txt | AC | 51 ms | 8448 KB |
1_24.txt | AC | 53 ms | 8448 KB |
1_25.txt | AC | 51 ms | 8448 KB |
1_26.txt | AC | 51 ms | 8448 KB |
1_27.txt | AC | 51 ms | 8320 KB |
1_28.txt | AC | 52 ms | 8448 KB |
1_29.txt | AC | 51 ms | 8448 KB |
1_30.txt | AC | 52 ms | 8320 KB |
1_31.txt | AC | 51 ms | 8448 KB |
1_32.txt | AC | 51 ms | 8448 KB |
1_33.txt | AC | 54 ms | 8448 KB |
1_34.txt | AC | 51 ms | 8576 KB |
1_35.txt | AC | 46 ms | 8064 KB |
1_36.txt | AC | 49 ms | 8320 KB |
1_37.txt | AC | 53 ms | 8576 KB |
1_38.txt | AC | 45 ms | 7808 KB |
1_39.txt | AC | 43 ms | 7552 KB |
1_40.txt | AC | 51 ms | 8448 KB |
1_41.txt | AC | 51 ms | 8576 KB |
1_42.txt | AC | 46 ms | 8064 KB |
1_43.txt | AC | 48 ms | 8064 KB |
1_44.txt | AC | 54 ms | 8576 KB |
1_45.txt | AC | 42 ms | 7424 KB |
1_46.txt | AC | 51 ms | 8576 KB |
1_47.txt | AC | 51 ms | 8448 KB |
1_48.txt | AC | 45 ms | 7936 KB |
1_49.txt | AC | 49 ms | 8448 KB |