제출 #49074

#제출 시각아이디문제언어결과실행 시간메모리
49074yusufake철인 이종 경기 (APIO18_duathlon)C++98
100 / 100
203 ms30748 KiB
#include<bits/stdc++.h> 
using namespace std; 

#define pb push_back
#define ll long long
const int N = 2e5 + 5; 

vector < int > U[N],V[N]; 

int AP[N],D[N],low[N],T,n,m,i,x,y,bcc;
stack < int > S; 
ll sz[N],asd,nn;

void f(int x, int p){
    ll t = sz[x] + U[x].size();
    for(auto y : U[x]){
	    f(y,x);
        sz[x] += sz[y];
        if(x > n)
            asd -= (t-1+(p!=-1)) * sz[y] * (sz[y]-1);
    }	
    if(x > n)
        asd -= t * (nn-sz[x]) * (nn-sz[x]-1);
}

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]){
  		nn = 0; g(i,-1); S.pop();
  		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) 메시지

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:52:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d%d",&x,&y);
    ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...