답안 #309558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309558 2020-10-03T19:34:54 Z bigg Mousetrap (CEOI17_mousetrap) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> grafo[MAXN];
int dp[MAXN];

pair<int, int > inserts(int x, pair<int, int> p){
	if(x > p.first) swap(p.first, p.second), p.first = x;
	else if(x > p.second) p.second = p.first;
	return p;
}

void dfs(int x, int p){
	pair<int, int> p_ = make_pair(-1, -1);
	for(int i = 0; i < grafo[x].size(); i++){
		int viz = grafo[x][i];
		if(viz == p) continue;
		dfs(viz, x);
		p_ inserts(dp[viz], p_);
	}
	if(grafo[x].size() == 1) dp[x] = 0;
	else if (grafo[x].size() == 2) dp[x] = 1;
	else dp[x] = p_.second + grafo[x].size() - 1; 
}
int n, t, m;
int main(){
	scanf("%d %d %d", &n, &t, &m);
	if(n == 1){
		printf("0\n");
		return 0;
	}
	for(int i = 1; i < n; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}
	dfs(t, 0);
	printf("%d\n",dp[m] );
}

Compilation message

mousetrap.cpp: In function 'void dfs(int, int)':
mousetrap.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i = 0; i < grafo[x].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~~
mousetrap.cpp:19:5: error: expected ';' before 'inserts'
   19 |   p_ inserts(dp[viz], p_);
      |     ^~~~~~~~
      |     ;
mousetrap.cpp:19:3: warning: statement has no effect [-Wunused-value]
   19 |   p_ inserts(dp[viz], p_);
      |   ^~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d %d %d", &n, &t, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~