답안 #131255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131255 2019-07-16T21:40:08 Z arthurconmy 악어의 지하 도시 (IOI11_crocodile) C++14
46 / 100
4 ms 760 KB
/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>

#ifndef ARTHUR_LOCAL
	#include "crocodile.h"
#endif

using namespace std;

using ll = long long;
#define ff first
#define ss second

const int MAXN=1001;
vector<pair<int,ll>> adj[MAXN];
bool vis[MAXN];
bool leaf[MAXN];

void update(ll NEW, ll &FIR, ll &SEC)
{
	if(NEW<=FIR)
	{
		SEC=FIR;
		FIR=NEW;
	}

	else
	{
		SEC=min(SEC,NEW);
	}
}

ll dfs(int v)
{
	vis[v]=1;

	ll best=1e18;
	ll second_best=1e18;

	for(auto u:adj[v])
	{
		if(vis[u.ff]) continue;

		if(leaf[u.ff])
		{
			update(u.ss, best, second_best);
		}

		else
		{
			update(u.ss+dfs(u.ff), best, second_best);
		}
	}

	return second_best;
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	for(int i=0; i<N-1; i++)
	{
		adj[R[i][0]].push_back(make_pair(R[i][1],ll(L[i])));
		adj[R[i][1]].push_back(make_pair(R[i][0],ll(L[i])));
	}

	for(int i=0; i<K; i++)
	{
		leaf[P[i]]=1;
	}

	return dfs(0);

	ll ans=0;

	for(int i=0; i<N; i++)
	{
		if(!leaf[i])
		{
			ll cur=dfs(i);
			// cout << i << " " << cur << endl;
			ans=max(ans,cur);

			for(int j=0; j<N; j++)
			{
				vis[j]=0;
			}
		}
	}

	return ans;
}

// int R[9][2];
// int L[9];
// int P[6];

// int main()
// {
// 	#ifdef ARTHUR_LOCAL
// 		ifstream cin("input.txt");
// 	#endif

// 	R[0][0]=0;
// 	R[0][1]=1;
// 	R[1][0]=0;
// 	R[1][1]=2;
// 	R[2][0]=0;
// 	R[2][1]=3;
// 	R[3][0]=1;
// 	R[3][1]=4;
// 	R[4][0]=1;
// 	R[4][1]=5;
// 	R[5][0]=2;
// 	R[5][1]=6;
// 	R[6][0]=2;
// 	R[6][1]=7;
// 	R[7][0]=3;
// 	R[7][1]=8;
// 	R[8][0]=3;
// 	R[8][1]=9;

// 	L[0]=4;
// 	L[1]=6;
// 	L[2]=2;
// 	L[3]=1;
// 	L[4]=8;
// 	L[5]=3;
// 	L[6]=9;
// 	L[7]=7;
// 	L[8]=5;

// 	P[0]=4;
// 	P[1]=5;
// 	P[2]=6;
// 	P[3]=7;
// 	P[4]=8;
// 	P[5]=9;

// 	cout << travel_plan(10,9,R,L,6,P) << endl;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Incorrect 4 ms 760 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Incorrect 4 ms 760 KB Output isn't correct
10 Halted 0 ms 0 KB -