# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49592 | mohammad_kilani | 철인 이종 경기 (APIO18_duathlon) | C++17 | 120 ms | 14324 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 200000000
const int N = 100010;
const int M = 100010;
int n , m ,comp[N] , num[N] , comp_cnt = 0 , u , v , dfs_cnt = 0 , dfs_low[N] , dfs_num[N] , num1[N] , num2[N] ;
bool vis[N] ;
long long all = 0 , ans = 0;
vector< int > g[N] ;
void DFS1(int node){
comp[node] = comp_cnt;
num[comp_cnt]++;
vis[node] = true;
for(int i=0;i<g[node].size();i++){
if(vis[g[node][i]] == false)
DFS1(g[node][i]);
}
}
void DFS(int node, int prnt){
dfs_low[node] = dfs_num[node] = dfs_cnt++;
num1[node] = 1;
num2[node] = 1;
vis[node] = true;
for(int i=0;i<g[node].size();i++){
if(g[node][i] == prnt) continue;
if(vis[g[node][i]]){
dfs_low[node] = min(dfs_low[node],dfs_num[g[node][i]]);
continue;
}
DFS(g[node][i],node);
dfs_low[node] = min(dfs_low[node],dfs_low[g[node][i]]);
num1[node] += num1[g[node][i]];
if(dfs_low[g[node][i]] == dfs_num[node]){
ans += (long long)num2[g[node][i]] * (num2[g[node][i]] + 1) * (num2[g[node][i]] - 1);
all -= (long long)num2[g[node][i]] * (num2[g[node][i]] + 1) * (num2[g[node][i]] - 1) / 6;
ans += (long long)(num[comp[node]] - (1 + num1[g[node][i]])) * num1[g[node][i]] * 2;
all -= (long long)(num[comp[node]] - (1 + num1[g[node][i]])) * num1[g[node][i]];
}
else if(dfs_low[g[node][i]] < dfs_num[node]){
num2[node] += num2[g[node][i]];
}
else{
ans += (long long)(num[comp[node]] - (1 + num1[g[node][i]])) * num1[g[node][i]] * 2;
all -= (long long)(num[comp[node]] - (1 + num1[g[node][i]])) * num1[g[node][i]];
}
}
}
int main() {
scanf("%d%d",&n,&m);
for(int i=0;i<m;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] == false){
DFS1(i);
all += (long long)num[comp_cnt] * (num[comp_cnt] - 1) * (num[comp_cnt] - 2) / 6;
comp_cnt++;
}
}
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++){
if(vis[i] == false)
DFS(i,-1);
}
ans += (long long)all * 4;
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |