Submission #1365230
Source Code Expand
//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 Info
Submission Time | |
---|---|
Task | F - Blackout |
User | xiqiao |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1176 Byte |
Status | WA |
Exec Time | 56 ms |
Memory | 19456 KB |
Compile Error
./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); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 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 | 38 ms | 19328 KB |
1_05.txt | WA | 38 ms | 19328 KB |
1_06.txt | AC | 38 ms | 19328 KB |
1_07.txt | WA | 38 ms | 19328 KB |
1_08.txt | WA | 38 ms | 19328 KB |
1_09.txt | AC | 38 ms | 19456 KB |
1_10.txt | WA | 37 ms | 19328 KB |
1_11.txt | AC | 38 ms | 19328 KB |
1_12.txt | WA | 38 ms | 19328 KB |
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 | 19 ms | 6272 KB |
1_18.txt | WA | 55 ms | 11264 KB |
1_19.txt | WA | 49 ms | 11264 KB |
1_20.txt | WA | 49 ms | 11264 KB |
1_21.txt | WA | 49 ms | 11264 KB |
1_22.txt | WA | 45 ms | 11264 KB |
1_23.txt | WA | 47 ms | 11264 KB |
1_24.txt | WA | 45 ms | 11136 KB |
1_25.txt | WA | 49 ms | 11264 KB |
1_26.txt | WA | 48 ms | 11264 KB |
1_27.txt | WA | 46 ms | 11136 KB |
1_28.txt | WA | 50 ms | 11264 KB |
1_29.txt | WA | 46 ms | 11264 KB |
1_30.txt | WA | 46 ms | 11136 KB |
1_31.txt | WA | 50 ms | 11264 KB |
1_32.txt | WA | 56 ms | 11264 KB |
1_33.txt | WA | 46 ms | 11264 KB |
1_34.txt | WA | 47 ms | 11008 KB |
1_35.txt | WA | 40 ms | 9728 KB |
1_36.txt | WA | 42 ms | 10624 KB |
1_37.txt | WA | 48 ms | 11264 KB |
1_38.txt | WA | 38 ms | 9088 KB |
1_39.txt | WA | 36 ms | 8832 KB |
1_40.txt | WA | 45 ms | 11264 KB |
1_41.txt | WA | 45 ms | 11264 KB |
1_42.txt | WA | 41 ms | 10240 KB |
1_43.txt | WA | 41 ms | 9856 KB |
1_44.txt | WA | 46 ms | 11136 KB |
1_45.txt | WA | 35 ms | 8320 KB |
1_46.txt | WA | 47 ms | 11264 KB |
1_47.txt | WA | 46 ms | 11264 KB |
1_48.txt | WA | 39 ms | 9472 KB |
1_49.txt | WA | 42 ms | 10624 KB |