답안 #486604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486604 2021-11-12T05:56:05 Z kiomi 관광지 (IZhO14_shymbulak) C++17
0 / 100
50 ms 29348 KB
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")

//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)
//logb(n)=loga(n)/loga(b)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

//(a+b)^n=sum of C(n,i)*a^i*b^(n-i) 0<=i<=n
//(a-b)^n=sum of C(n,i)*a^i*b^(n-i) for even i-for odd i

#define gainf pop_front
#define len(x) (int)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0
// a^b=(a+b)-2(a&b)

typedef double db;
typedef long long ll;

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

const int ary=1e6+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
int n,p[ary],c[ary],k[ary],e[ary],d[ary],ans,mx;
vector<int> g[ary],q,r,t;
void dfs(int v=1){
	c[v]=1;
	for(int i=0;i<len(g[v]);i++){
		int to=g[v][i];
		if(to==p[v]){
			continue;
		}
		if(c[to]==2){
			continue;
		}
		if(!c[to]){
			p[to]=v;
			dfs(to);
			continue;
		}
		int u=v;
		while(1){
			q.push_back(u);
			k[u]=len(q);
			if(u==to){
				break;
			}
			u=p[u];
		}
	}
	c[v]=2;
}
void go(int v,int pr=0){
	for(int i=0;i<len(r);i++){
		int x=min(abs(k[e[v]]-k[e[r[i]]]),len(q)-abs(k[e[v]]-k[e[r[i]]]));
		if(x+d[v]+d[r[i]]>mx){
			ans=0;
			mx=x+d[v]+d[r[i]];
		}
		if(x+d[v]+d[r[i]]==mx){
			ans++;
			ans+=(abs(k[e[v]]-k[e[r[i]]])==len(q)-abs(k[e[v]]-k[e[r[i]]]));
		}
	}
	t.push_back(v);
	for(int i=0;i<len(g[v]);i++){
		int to=g[v][i];
		if(to==pr||k[to]){
			continue;
		}
		d[to]=d[v]+1;
		e[to]=e[v];
		go(to,v);
	}
}
void run(int v,int pr=0,int cnt=0){
	if(d[v]>mx){
		ans=0;
		mx=d[v];
	}
	if(d[v]==mx){
		ans++;
	}
	for(int i=0;i<len(g[v]);i++){
		int to=g[v][i];
		if(to==pr||cnt+(k[to]>0)==2){
			continue;
		}
		d[to]=d[v]+1;
		run(to,v,cnt+(k[to]>0));
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs();
	for(int i=0;i<len(q);i++){
		e[q[i]]=q[i];
		go(q[i]);
		while(len(t)){
			r.push_back(t.back());
			t.pop_back();
		}
	}
	/*for(int i=1;i<=n;i++){
		if(k[i]){
			continue;
		}
		d[i]=0;
		run(i);
	}*/
	cout<<ans;
}

Compilation message

shymbulak.cpp:15: warning: "full" redefined
   15 | #define full(x) x.begin(),x.end()
      | 
shymbulak.cpp:14: note: this is the location of the previous definition
   14 | #define full(x,n) x,x+n+1
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Incorrect 10 ms 23720 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23884 KB Output is correct
2 Incorrect 13 ms 23888 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 29348 KB Output isn't correct
2 Halted 0 ms 0 KB -