제출 #49073

#제출 시각아이디문제언어결과실행 시간메모리
49073yusufakeDuathlon (APIO18_duathlon)C++98
100 / 100
225 ms27516 KiB
#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   = 1e5 + 5; 

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

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

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 -= 1LL * (t-1+(p!=-1)) * sz[y] * (sz[y]-1);
    }	
    if(x > n)
        asd -= 1LL * 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 += 1LL * 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:54:12: 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...