QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#676714#6438. CrystalflyLyniaWA 0ms3596kbC++234.3kb2024-10-25 23:25:552024-10-25 23:25:56

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 23:25:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-10-25 23:25:55]
  • 提交

answer

///////////        
//                   //      //
//              ////////////////////
//                   //      //
//                 
///////////

//          
//          
//           //     //    ////////     /\     /////////
//           //     //   //      //          //       //
//            ////////   //      //    //    //       //
//                  //   //      //    //    //       //
//////////   ////////    //      //    //     /////////////

//#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <list>
#include <stack>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <random>
#include <numeric>
#include <functional>
//#include <Windows.h>

using namespace std;

#define fa(i,op,n) for (int i = op; i <= n; i++)
#define fb(j,op,n) for (int j = op; j >= n; j--)
#define pb push_back
#define HashMap unordered_map
#define HashSet unordered_set
#define var auto
#define all(i) i.begin(), i.end()
#define all1(i) i.begin() + 1,i.end()
#define endl '\n'
#define px first
#define py second
#define DEBUG(a) cout<<a<<endl

using VI = vector<int>;
using VL = vector<long long>;
using ll = long long;
using ull = unsigned long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
	out << '(' << p.first << ", " << p.second << ')';
	return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& ve) {
	for (T i : ve)
		out << i << ' ';
	return out;
}

template<class T1, class T2>
ostream& operator<<(ostream& out, const map<T1, T2>& mp) {
	for (auto i : mp)
		out << i << '\n';
	return out;
}

const int INF = 0x3f3f3f3f;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
const int IINF = 0x7fffffff;
const int iinf = 0x80000000;
const ll LINF = 0x7FFFFFFFFFFFFFFF;
const ll linf = 0x8000000000000000;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };

//#include "Lynia.h"
namespace MyTools
{

}

namespace MT = MyTools;
//using Math = MT::Math<ll>;
//using mint = MT::ModInt<998244353>;

const int mod = 1e9 + 7;
const int N = 1e6 + 10;


void solve(int CASE)
{
	int n; cin >> n;
	var a = vector<ll>(n + 1);
	var t = vector<int>(n + 1);
	fa(i, 1, n)cin >> a[i];
	fa(i, 1, n)cin >> t[i];
	var g = vector<vector<int>>(n + 1);
	fa(i, 1, n - 1) {
		int u, v; cin >> u >> v;
		g[u].pb(v);
	}

	var dp = vector<ll>(n + 1, 0);
	var dfs = [&](var dfs, int now)->void {
		dp[now] = a[now];
		if (g[now].size() == 0)return;

		// 1:a[u], 2: dp[u] - a[u], 3: dp[u]
		// t[u] t[v]  
		//   1    i    dp[v] + dp[u] - a[u]
		//   2    i    dp[v] + dp[u] - a[u]
		//   3    i    dp[v] + dp[u]
		set<pll, greater<pll>>_1, _2, _3;

		ll mxdp = 0;
		for (int to : g[now]) {
			dfs(dfs, to);
			mxdp = max(mxdp, dp[to]);
			if (t[to] == 3)_3.insert({ dp[to],to });
			else _2.insert({ dp[to] - a[to],to });
			_1.insert({ dp[to],to });
		}

		ll res = mxdp;
		if (g[now].size() > 1) {
			// 先处理 _3
			if (_3.size()) {
				var v3be = _3.begin()->py;
				var v1be = _1.begin()->py;
				if (v1be == v3be) { // _3.size() = [1,n]
					if (_3.size() == 1) {
						res = max(
							res,
							_3.begin()->px + (++_1.begin())->px
						);
					}
					else {
						res = max({
							res,
							_3.begin()->px + (++_1.begin())->px,
							(++_3.begin())->px + _1.begin()->px,
							});
					}
				}
				else { // _3.size() = [2,n]
					res = max(
						res,
						_3.begin()->px + _1.begin()->px
					);
				}
			}

			var v2be = _2.begin()->py;
			var v1be = _1.begin()->py;
			if (v1be == v2be) {
				res = max({
					res,
					_2.begin()->px + (++_1.begin())->px,
					(++_2.begin())->px + _1.begin()->px,
					});
			}
			else {
				res = max(
					res,
					_2.begin()->px + _1.begin()->px
				);
			}
		}
		dp[now] += res;
		};
	dfs(dfs, 1);
	cout << dp[1] << endl;
	return;
}

int main()
{
	//SetConsoleOutputCP(CP_UTF8);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int _ = 1;
	cin >> _;
	fa(i, 1, _)solve(i);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3484kb

input:

2
5
1 10 100 1000 10000
1 2 1 1 1
1 2
1 3
2 4
2 5
5
1 10 100 1000 10000
1 3 1 1 1
1 2
1 3
2 4
2 5

output:

10101
10111

result:

ok 2 number(s): "10101 10111"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3596kb

input:

10
6
8 1 1 5 8 9
2 1 2 2 2 2
1 2
2 3
2 4
1 5
2 6
6
6 4 4 1 3 6
2 1 3 3 3 3
1 2
1 3
3 4
4 5
5 6
6
10 5 1 8 5 1
1 3 1 2 2 2
1 2
2 3
2 4
2 5
3 6
10
6 8 8 9 6 9 5 6 6 4
2 1 3 3 2 2 2 2 3 1
1 2
1 3
3 4
4 5
5 6
4 7
2 8
7 9
9 10
7
10 9 1 5 7 5 4
1 1 1 2 1 3 2
1 2
1 3
3 4
3 5
5 6
1 7
5
7 1 1 4 2
3 1 3 2 2
1...

output:

25
24
24
62
31
15
16
24
19
19

result:

wrong answer 4th numbers differ - expected: '56', found: '62'