# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
49072 | yusufake | 철인 이종 경기 (APIO18_duathlon) | C++98 | 219 ms | 36604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;
vector < int > U[N],V[N];
ll AP[N],D[N],low[N],T,sz[N],n,m,i,x,y,nn,asd,bcc,a;
stack < int > S;
void f(int x, int p){
ll t = sz[x] + U[x].size();
for(auto y : U[x]){
if(y == p) continue;
f(y,x);
sz[x] += sz[y];
if(x > n){
asd -= a = (t-1+(p!=-1)) * sz[y] * (sz[y]-1);
//cout << x << " " << a << " " << t << " -\n";
}
}
if(x > n) {
asd -= a = t * (nn-sz[x]) * (nn-sz[x]-1);
//cout << x << " " << a << " -\n";
}
}
void g(int x, int p){
D[x] = low[x] = ++T; nn++;
S.push(x);
AP[x] = p == -1 ? -1 : 0;
for(auto y : V[x]){
if(!D[y]){
g(y,x);
low[x] = min(low[x] , low[y]);
if(low[y] >= D[x]){
AP[x]++;
sz[x] = 1;
U[x].pb(++bcc);
for(int z = 0; z != y ;){
z = S.top();
S.pop();
if(AP[z]) U[bcc].pb(z);
else sz[bcc]++;
}
}
}
else if(y != p) low[x] = min(low[x] , D[y]);
}
}
int main(){
cin >> n >> m;
for(;m--;){
scanf("%d%d",&x,&y);
V[x].pb(y); V[y].pb(x);
}
bcc = n;
for(i=1;i<=n;i++)
if(!D[i]){
for(;S.size();) S.pop();
nn = 0; g(i,-1);
asd += nn * (nn-1) * (nn-2);
if(AP[i]) f(i,-1);
else{
x = U[i][0]; sz[x]++; f(x,-1);
}
}
cout << asd;
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... |