QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398053#8591. ShopsTalaodi0 226ms62232kbC++235.5kb2024-04-24 21:35:102024-04-24 21:35:12

Judging History

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

  • [2024-04-24 21:35:12]
  • 评测
  • 测评结果:0
  • 用时:226ms
  • 内存:62232kb
  • [2024-04-24 21:35:10]
  • 提交

answer

#include <bits/stdc++.h>

namespace IO {
	template <class Stream>
	void write_int128(Stream& out, __int128 v) {
		if (v >= 10) {
			write_int128(out, v / 10);
		}
		out << (int) (v % 10);
	}

	template <class Stream>
	Stream& fmtbase(Stream& out, const char* format) {
		for (; *format; format++) {
			if (*format == '{' && *(format + 1) == '}') {
				throw std::invalid_argument("Error Number of Parameters!");
			}
			
			out << *format;
		}
		
		return out;
	}
	
	template <class Stream, class... Nxt>
	Stream& fmtbase(Stream& out, const char* format, const __int128& value, const Nxt&... nxt) {
		for (; *format; format++) {
			if (*format == '{' && *(format + 1) == '}') {
				write_int128(out, value);
				return fmtbase(out, format + 2, nxt...);
			} 
			
			out << *format;
		}
		
		throw std::invalid_argument("Error Number of Parameters!");
	}

	template <class Stream, class Fst, class... Nxt>
	Stream& fmtbase(Stream& out, const char* format, const Fst& value, const Nxt&... nxt) {
		for (; *format; format++) {
			if (*format == '{' && *(format + 1) == '}') {
				out << value;
				return fmtbase(out, format + 2, nxt...);
			} 
			
			out << *format;
		}
		
		throw std::invalid_argument("Error Number of Parameters!");
	}
	
	template <class... Ps>
	std::string to_string(const char* format, const Ps&... ps) {
		std::stringstream ss;
		fmtbase(ss, format, ps...);
		return ss.str();
	}

	template <class... Ps>
	std::ostream& fmtout(const char* format, const Ps&... ps) {
		return fmtbase(std::cout, format, ps...);
	}
	
	template <class... Ps>
	std::ostream& fmterr(const char* format, const Ps&... ps) {
		return fmtbase(std::cerr, format, ps...);
	}
	
	std::istream& allin() {
		return std::cin;
	}
	
	template <class Fst, class ... Nxt>
	std::istream& allin(Fst& fst, Nxt&... nxt) {
		std::cin >> fst;
		return allin(nxt...);
	}
	
	template <class Iter>
	std::istream& rangin(Iter begin, Iter end) {
		while (begin != end) {
			std::cin >> *begin;
			begin++;
		}
		
		return std::cin;
	}
	
	namespace Fast {
		bool sync = false;
		
		char buf[1 << 23];
		char *p1 = buf, *p2 = buf;
		
		void sync_with_ios(bool s) {
			sync = s;
		}
		
		inline char getchar() {
			if (sync) {
				return (char) std::cin.get();
			}
			else {
				return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 22, stdin)), p1 == p2 ? EOF : *p1++;
			}
		}
		
		void read() { }
		
		template <class T, class... U>
		void read(T& x, U&... us) {
			x = 0;
			T pos = 1;
			
			char c = getchar();
			while (!isdigit(c)) {
				if (c == '-') {
					pos = -1;
				}
				
				c = getchar();
			}
			
			while (isdigit(c)) {
				x = 10 * x + c - '0';
				c = getchar();
			}
			
			x *= pos;
			read(us...);
		}
		
		template <class T>
		void write(const T& t) {
			if (t > 10) {
				write(t / 10);
			}
			
			std::cout << (int) (t % 10);
		}
	}
}

namespace Solve {
	#define int long long

	using namespace IO;

	using ll = long long;
	using ul = unsigned long long;
	using db = double;
	using ld = long double;
	using ui = unsigned;
	using ib = __int128;
	using ub = __uint128_t;

	int const INF = std::numeric_limits<int>::max();
	int const NINF = std::numeric_limits<int>::min();
	ll const LINF = std::numeric_limits<ll>::max();
	ll const LNINF = std::numeric_limits<ll>::min();
	ld const EPS = 1e-8;

	std::mt19937_64 mt;

	ll rnd(ll l, ll r) {
		return std::uniform_int_distribution<ll>(l, r)(mt);
	}

	template <class T>
	inline int isz(const T& v) {
		return v.size();
	}

	template <class T>
	inline T& ckmx(T& a, T b) {
		return a < b ? (a = b) : a;
	}

	template <class T>
	inline T& ckmi(T& a, T b) {
		return b < a ? (a = b) : a;
	}

	int const N = 5e5 + 10;

	struct Edge {
		int x, y, w;
	};

	struct Node {
		int x, v;
	};

	std::vector<Node> tr[N + 1];
	int fa[N + 1];
	Edge eds[N + 1];
	int n, m;
	int ans;
	int dep[N + 1];

	int get(int x) {
		return fa[x] == x ? x : fa[x] = get(fa[x]);
	}

	void dfs(int x, int fa) {
		dep[x] = dep[fa] + 1;
		int mi = INF;
		for (auto& to : tr[x]) {
			ckmi(mi, to.v);
			if (to.x != fa) {
				dfs(to.x, x);
			}
		}
		ckmx(ans, mi);
	}

	void main() {
		std::cin >> n >> m;
		for (int i = 1; i <= m; i++) {
			std::cin >> eds[i].x >> eds[i].y >> eds[i].w;
		}

		std::sort(eds + 1, eds + m + 1, [&](const Edge& a, const Edge& b) {
			return a.w < b.w;
		});

		for (int i = 1; i <= n; i++) {
			fa[i] = i;
		}

		for (int i = 1; i <= m; i++) {
			int x = get(eds[i].x);
			int y = get(eds[i].y);
			if (x != y) {
				tr[x].push_back({ y, eds[i].w });
				tr[y].push_back({ x, eds[i].w });
				fa[x] = y;
			}
		}

		dfs(1, 0);
		fmtout("{}\n", ans);
		for (int i = 1; i <= n; i++) {
			fmtout("{}", dep[i] % 2 ? "B" : "D");
		}
		fmtout("\n");
	}

	void init() {
		
	}

	void clear() {

	}
}

signed main() {
#ifndef ONLINE_JUDGE
	auto input_file = freopen("d.in", "r", stdin);
	auto output_file = freopen("d.out", "w", stdout);
#endif

	auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();

	IO::fmterr("seed: {}\n", seed);
	Solve::mt.seed(seed);

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

	int t = 1;
	// std::cin >> t;

	Solve::init();

	for (int id = 1; id <= t; id++) {
		Solve::main();
		Solve::clear();
	}

#ifndef ONLINE_JUDGE
	std::cout.flush();
	fclose(input_file);
	fclose(output_file);
#endif

	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 2ms
memory: 9744kb

input:

3 3
1 2 3
2 3 1
1 3 2

output:

2
BBD

result:

ok inconveniences = 2

Test #2:

score: 0
Accepted
time: 2ms
memory: 9668kb

input:

5 6
3 2 3
4 2 1
5 3 9
1 3 5
1 4 2
2 3 1

output:

9
BBDDB

result:

ok inconveniences = 9

Test #3:

score: -7
Wrong Answer
time: 22ms
memory: 13844kb

input:

8 135737
1 4 763713071
3 7 45141437
4 8 618418466
6 8 91803956
7 5 972595945
5 2 751163228
2 8 9886315
4 3 106470622
8 6 949495949
1 2 885918825
4 6 322040168
7 6 754489330
4 8 618968328
5 3 996860159
3 6 210132897
3 4 591744987
8 7 447985622
2 4 4833956
5 7 610154418
2 5 410116873
2 5 912717336
8 7...

output:

19258
BDDBBDDD

result:

wrong answer your claimed answer is 19258, but the inconveniences of your plan is actually 20770

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 226ms
memory: 62232kb

input:

500000 499999
1 2 776715136
2 3 406881694
3 4 265792290
4 5 507607272
5 6 182246639
6 7 997847597
7 8 164130256
8 9 278962226
9 10 411194641
10 11 363646402
11 12 672225656
12 13 494629089
13 14 717664153
14 15 121619271
15 16 476857704
16 17 301215244
17 18 810217743
18 19 850722975
19 20 10710274
...

output:

998789691
BDDBBDDBDDBBDBDDBDDBDDDBDDBDDBDDBDBBDDBDBDBBBDDBBBDDBDBBDDBDDBBDDBBDDBDBDBDDDDBDBDDBDBBDBBDBDDBDBDBDBDDDDBBDDBDBDBBDBBDBDBDBBDBBDBDBBDBDBDBDBDBDBBDBDBBDBBDBDBBDDBDDBDDBBDBDBDDBDDDBDDBDBDDDBDDBBDBDDBDBDDBBDBDBDDBDDBDDDBBDBBBDDDBDBDBBDBDBBDBDDDDDBDBBDDDBDBBBBDBDBDDBDBBDBBDBDDBDDBDBDBDDBBDDDB...

result:

wrong answer your claimed answer is 998789691, but the inconveniences of your plan is actually 2568579228

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 103ms
memory: 53760kb

input:

366489 397001
2 127909 1
7 171229 1
8 158597 1
11 282213 1
14 356007 1
15 286102 1
16 93205 1
17 260111 1
18 138962 1
20 359938 1
29 223905 1
31 357684 1
32 259968 1
34 65205 1
37 200276 1
41 83195 1
43 159858 1
48 332277 1
50 320322 1
51 338467 1
53 262785 1
55 83815 1
56 173198 1
58 169473 1
63 19...

output:

1
BBDBDBDDBDDBBDBBDDDBDDDBDDBBBBBDDDDDDBDBDBDBBBDDBBDDBBDDBDDDBDBDDBBBBBDDBBBBDBDBDBBDBBDBBDBBDBBBBDBBBBBDBBBBBBBBDBBDBDBDDDBBBDBDDDDBBDBDBDDDDBBDDDDDBDDBDBDDBDDBDBBDBBDBDDBDBBBBBBBBBBDDDBDBBDDDDDBDBBDBDDDBDDDDDDBDDDBBDDBDDBDDDDDDBDDDDDBDBDDDBDBDBDDBBDDDDDDDBDBDDBDDDBBBBDDBDDBBBDBDDBBDDBBDDDDDDBDDBB...

result:

wrong answer your claimed answer is 1, but the inconveniences of your plan is actually 13

Subtask #5:

score: 0
Skipped

Dependency #1:

0%