답안 #484537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484537 2021-11-04T09:29:04 Z BackNoob 악어의 지하 도시 (IOI11_crocodile) C++14
46 / 100
118 ms 262148 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1) 
#define TASK "task"
#define sz(s) (int) (s).size()

using namespace std;
const int mxN = 3e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

int n , m , k;
vector<pair<int , int>> adj[mxN];
bool exitnode[mxN];
ll dp[mxN];

void dfs(int u , int par)
{
	ll best1 , best2;
	best1 = best2 = infll;
	bool isleaf = true;
	for(auto it : adj[u]) {
		int v = it.fi;
		int c = it.se;
		if(v == par) continue;
		isleaf = false;
		dfs(v , u);
		if(best1 > dp[v] + c) {
			best2 = best1;
			best1 = dp[v] + c;
		}
		else minimize(best2 , dp[v] + c);
	}
	if(isleaf == true && exitnode[u] == true) dp[u] = 0;
	else dp[u] = best2;
}



ll travel_plan(int n , int m , int r[][2] , int l[] , int k , int p[])
{	
	for(int i = 0 ; i < m ; i++) {
		int u = r[i][0];
		int v = r[i][1];
		int c = l[i];
		++u; ++v;
		adj[u].pb({v , c});
		adj[v].pb({u , c});
	}

	for(int i = 0 ; i < k ; i++) {
		exitnode[p[i] + 1] = true;
	}

	dfs(1 , -1);
	return dp[1];
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7420 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7420 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Runtime error 118 ms 262148 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 5 ms 7376 KB Output is correct
4 Correct 6 ms 7420 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Runtime error 118 ms 262148 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -