답안 #76472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76472 2018-09-13T15:00:37 Z hamzqq9 Torrent (COI16_torrent) C++14
0 / 100
552 ms 21292 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 60000000000000000
#define MOD 1000000009
#define N 300005
#define MAX 5032117	
#define LOG 30
#define KOK 333
using namespace std;

int tut,n,a,b,x,y;
vector<int> tr,alle,v[N];

int dfs(int node,int ata,bool state) {

	int mx=-1,cnt=0;

	for(int to:v[node]) {

		if(to==ata || (!state && to==alle[tut+1]) || (state && to==alle[tut])) continue ;

		int res=dfs(to,node,state);

		if(res>mx) {

			mx=res;
			cnt=1;

		}
		else if(res==mx) cnt++;

	}

	if(mx==-1) mx=cnt=0;

	return mx+cnt;

}

int solve(int upto) {

	tut=upto;

	return max(dfs(a,0,0),dfs(b,0,1));

}

void process() {

	for(int i:tr) alle.pb(i);

}

void dfs1(int node,int ata) {

	tr.pb(node);

	if(node==b) {

		process();

		return ;

	} 

	for(int i:v[node]) {

		if(i==ata) continue ;

		dfs1(i,node);

	}

	tr.ppb();

}

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%d %d %d",&n,&a,&b);

	for(int i=1;i<n;i++) {

		scanf("%d %d",&x,&y);

		v[x].pb(y);
		v[y].pb(x);

	}

	dfs1(a,0);

	int bas=0,son=sz(alle)-2;

	while(bas+1<=son) {

		int res1=solve(orta);
		int res2=solve(orta+1);

		if(res1<res2) son=orta;
		else bas=orta+1;

	}

	printf("%d\n",min(min(solve(0),solve(sz(alle)-2)),solve(orta)));

}

Compilation message

torrent.cpp: In function 'int main()':
torrent.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&a,&b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
torrent.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 7416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 552 ms 21292 KB Output isn't correct
2 Halted 0 ms 0 KB -