# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
55688 | 2018-07-08T15:15:45 Z | mohammad_kilani | 철인 이종 경기 (APIO18_duathlon) | C++17 | 183 ms | 53708 KB |
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 1000000000 const int N = 100010; int n , m , u , v , dfs_low[N] , dfs_num[N] , dfs_cnt = 0 , all[N], comp[N] , comp_cnt = 0; vector< int > g[N] ; bool vis[N]; long long ans = 0; void DFS2(int node){ vis[node] = true; comp[node] = comp_cnt; all[comp_cnt]++; for(int i=0;i<g[node].size();i++){ if(!vis[g[node][i]]) DFS2(g[node][i]); } } pair<int,int> DFS(int node,int prnt){ dfs_low[node] = dfs_num[node] = ++dfs_cnt; int num1 = 1 , num2 = 1 , num3 = all[comp[node]] - 1; pair<int,int> tmp; for(int i=0;i<g[node].size();i++){ if(g[node][i] == prnt) continue; if(dfs_num[g[node][i]] != 0){ dfs_low[node] = min(dfs_low[node],dfs_num[g[node][i]]); continue; } tmp = DFS(g[node][i],node); num3 -= tmp.first; num1 += tmp.first; dfs_low[node] = min(dfs_low[node],dfs_low[g[node][i]]); if(dfs_low[g[node][i]] >= dfs_num[node]){ ans += (long long)tmp.first * num3 * 2; ans += (long long)(tmp.second + 1) * tmp.second * (tmp.second - 1); ans += (long long)tmp.second * (tmp.second - 1) * num3 * 2; } else{ num2 += tmp.second; } } return make_pair(num1,num2); } int main(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++){ scanf("%d%d",&u,&v); g[u].push_back(v); g[v].push_back(u); } for(int i=1;i<=n;i++){ if(!vis[i]){ DFS2(i); comp_cnt++; } } for(int i=1;i<=n;i++){ if(dfs_num[i] == 0) DFS(i,-1); } cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2808 KB | Output is correct |
2 | Incorrect | 4 ms | 2920 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2808 KB | Output is correct |
2 | Incorrect | 4 ms | 2920 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 183 ms | 16380 KB | Output is correct |
2 | Correct | 133 ms | 17644 KB | Output is correct |
3 | Correct | 100 ms | 17644 KB | Output is correct |
4 | Correct | 135 ms | 18332 KB | Output is correct |
5 | Correct | 88 ms | 18332 KB | Output is correct |
6 | Correct | 81 ms | 18332 KB | Output is correct |
7 | Correct | 134 ms | 18332 KB | Output is correct |
8 | Correct | 131 ms | 19612 KB | Output is correct |
9 | Correct | 122 ms | 19612 KB | Output is correct |
10 | Correct | 135 ms | 21468 KB | Output is correct |
11 | Correct | 121 ms | 21468 KB | Output is correct |
12 | Correct | 116 ms | 22284 KB | Output is correct |
13 | Correct | 102 ms | 23452 KB | Output is correct |
14 | Correct | 111 ms | 24336 KB | Output is correct |
15 | Correct | 90 ms | 25016 KB | Output is correct |
16 | Correct | 86 ms | 25600 KB | Output is correct |
17 | Correct | 65 ms | 25600 KB | Output is correct |
18 | Correct | 68 ms | 25600 KB | Output is correct |
19 | Correct | 70 ms | 25600 KB | Output is correct |
20 | Correct | 67 ms | 25600 KB | Output is correct |
21 | Correct | 72 ms | 25600 KB | Output is correct |
22 | Correct | 65 ms | 25600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 25600 KB | Output is correct |
2 | Correct | 5 ms | 25600 KB | Output is correct |
3 | Correct | 5 ms | 25600 KB | Output is correct |
4 | Correct | 5 ms | 25600 KB | Output is correct |
5 | Correct | 5 ms | 25600 KB | Output is correct |
6 | Correct | 5 ms | 25600 KB | Output is correct |
7 | Correct | 5 ms | 25600 KB | Output is correct |
8 | Correct | 5 ms | 25600 KB | Output is correct |
9 | Correct | 4 ms | 25600 KB | Output is correct |
10 | Correct | 5 ms | 25600 KB | Output is correct |
11 | Correct | 5 ms | 25600 KB | Output is correct |
12 | Correct | 4 ms | 25600 KB | Output is correct |
13 | Correct | 4 ms | 25600 KB | Output is correct |
14 | Correct | 4 ms | 25600 KB | Output is correct |
15 | Correct | 4 ms | 25600 KB | Output is correct |
16 | Correct | 4 ms | 25600 KB | Output is correct |
17 | Correct | 4 ms | 25600 KB | Output is correct |
18 | Correct | 4 ms | 25600 KB | Output is correct |
19 | Correct | 4 ms | 25600 KB | Output is correct |
20 | Correct | 4 ms | 25600 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 27188 KB | Output is correct |
2 | Correct | 138 ms | 28492 KB | Output is correct |
3 | Correct | 130 ms | 29704 KB | Output is correct |
4 | Correct | 77 ms | 30968 KB | Output is correct |
5 | Correct | 78 ms | 32216 KB | Output is correct |
6 | Correct | 179 ms | 37688 KB | Output is correct |
7 | Correct | 155 ms | 37688 KB | Output is correct |
8 | Correct | 156 ms | 37936 KB | Output is correct |
9 | Correct | 153 ms | 38488 KB | Output is correct |
10 | Correct | 70 ms | 38488 KB | Output is correct |
11 | Correct | 77 ms | 39708 KB | Output is correct |
12 | Correct | 69 ms | 40916 KB | Output is correct |
13 | Correct | 87 ms | 42260 KB | Output is correct |
14 | Correct | 91 ms | 43536 KB | Output is correct |
15 | Correct | 109 ms | 44444 KB | Output is correct |
16 | Correct | 98 ms | 44972 KB | Output is correct |
17 | Correct | 79 ms | 46544 KB | Output is correct |
18 | Correct | 50 ms | 47748 KB | Output is correct |
19 | Correct | 139 ms | 49004 KB | Output is correct |
20 | Correct | 54 ms | 50244 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 50244 KB | Output is correct |
2 | Correct | 5 ms | 50244 KB | Output is correct |
3 | Incorrect | 7 ms | 50244 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 72 ms | 51272 KB | Output is correct |
2 | Correct | 133 ms | 52508 KB | Output is correct |
3 | Incorrect | 91 ms | 53708 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2808 KB | Output is correct |
2 | Incorrect | 4 ms | 2920 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 2808 KB | Output is correct |
2 | Incorrect | 4 ms | 2920 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |