QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#745071 | #5219. 随机树生成器 | hos_lyric# | 44 | 460ms | 35664kb | C++14 | 2.8kb | 2024-11-14 03:08:30 | 2024-11-14 03:08:30 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int N = 1000;
const vector<vector<int>> TSS{
{1, 2, 3, 4},
{1, 2},
{1, 2, 3},
{1, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
};
int O, M;
vector<vector<int>> A, B;
vector<vector<int>> graph;
pair<int, int> dfs(int u, int p) {
pair<int, int> ret(0, u);
for (const int v : graph[u]) if (p != v) {
auto res = dfs(v, u);
++res.first;
chmax(ret, res);
}
return ret;
}
int main() {
for (; ~scanf("%d", &O); ) {
scanf("%d", &M);
A.resize(M);
B.resize(M);
for (int m = 0; m < M; ++m) {
A[m].resize(N - 1);
B[m].resize(N - 1);
for (int i = 0; i < N - 1; ++i) {
scanf("%d%d", &A[m][i], &B[m][i]);
--A[m][i];
--B[m][i];
}
}
vector<pair<double, int>> fms(M);
for (int m = 0; m < M; ++m) {
graph.assign(N, {});
for (int i = 0; i < N - 1; ++i) {
const int u = A[m][i];
const int v = B[m][i];
graph[u].push_back(v);
graph[v].push_back(u);
}
const auto res0 = dfs(0, -1);
const auto res1 = dfs(res0.second, -1);
const int d = res1.first;
int c = 0;
for (int u = 0; u < N; ++u) if (graph[u].size() == 1) ++c;
fms[m] = make_pair(d - 0.567 * c, m);
}
sort(fms.begin(), fms.end());
const auto &ts = TSS[O];
assert(M % (int)ts.size() == 0);
vector<int> ans(M, 0);
for (int i = 0; i < M; ++i) {
ans[fms[i].second] = ts[i / (M / (int)ts.size())];
}
for (int m = 0; m < M; ++m) {
printf("%d\n", ans[m]);
}
}
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 20
Accepted
time: 228ms
memory: 19724kb
input:
1 2000 108 829 559 321 202 439 722 254 969 38 682 607 7 289 4 515 960 182 738 434 884 235 948 715 201 396 41 593 343 602 784 70 69 573 764 136 320 908 475 571 16 273 792 656 636 423 800 685 43 560 117 436 368 645 713 116 750 549 60 950 435 460 175 572 874 628 878 408 497 865 994 833 761 21 257 541 8...
output:
1 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 2 1 2 2 2 1 2 2 1 2 2 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 2 1 1 2 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 1 1 1 2 2 1 2 2 2 2 1 1 1 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 2 1 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 2 1 2 2 2 1 2 1 2 1 1 1 1 2 ...
result:
ok wrong 0 "ok" 10
Test #2:
score: 8
Acceptable Answer
time: 332ms
memory: 27920kb
input:
2 3000 385 547 858 608 546 731 753 57 849 806 659 442 208 260 844 77 344 530 171 29 278 228 863 72 379 395 554 829 488 650 554 281 139 67 190 479 894 587 819 872 936 543 862 985 99 202 778 317 317 500 41 420 713 562 616 863 691 743 673 49 702 705 358 910 254 665 617 579 142 926 433 634 446 299 647 8...
output:
2 3 1 1 1 2 3 1 2 1 2 3 2 2 3 1 3 1 2 2 1 3 3 2 1 3 3 1 1 1 2 2 1 3 1 2 3 3 2 3 3 1 2 1 2 2 1 1 2 3 2 1 3 2 2 2 1 2 3 1 2 2 1 3 2 3 1 3 1 1 2 2 2 3 1 2 3 3 3 3 3 3 2 3 3 3 2 3 2 3 2 2 3 2 3 1 3 2 1 3 3 3 1 2 2 2 2 3 3 3 3 2 1 3 2 2 1 2 1 2 3 2 3 1 1 1 2 3 2 2 1 2 3 3 1 3 2 1 1 1 2 1 1 3 2 1 2 2 2 2 ...
result:
points 0.40 wrong 62 "ok" 4
Test #3:
score: 8
Acceptable Answer
time: 350ms
memory: 27924kb
input:
3 3000 919 530 286 438 406 142 171 904 81 225 259 921 109 783 590 200 601 353 448 647 914 29 122 830 926 632 604 1 408 599 624 276 156 744 269 895 965 962 17 789 210 90 283 203 25 294 167 916 945 707 673 840 769 947 272 879 836 341 175 506 753 813 889 328 908 477 156 638 166 835 127 235 369 528 896 ...
output:
4 4 3 4 1 4 4 3 4 4 4 3 4 3 3 3 1 3 3 4 4 4 4 3 4 4 3 4 3 1 4 3 3 4 1 4 1 3 3 4 1 1 1 3 1 3 1 1 4 4 1 3 1 1 1 4 3 4 3 1 3 1 3 1 3 1 1 3 4 3 3 1 1 1 1 1 4 4 3 3 3 3 4 4 3 1 1 1 3 1 3 3 1 1 1 1 1 1 3 4 3 3 4 3 4 1 4 4 1 3 3 1 3 1 1 3 4 3 4 3 1 1 1 3 1 4 1 1 4 4 3 3 1 3 3 4 3 4 4 1 4 3 3 4 3 3 4 4 1 1 ...
result:
points 0.40 wrong 54 "ok" 4
Test #4:
score: 8
Acceptable Answer
time: 449ms
memory: 35664kb
input:
4 4000 491 790 856 346 110 718 170 643 428 723 333 382 373 986 352 227 190 993 896 507 660 720 691 733 867 854 136 794 208 769 739 362 431 624 608 1000 576 185 268 330 944 962 10 631 791 594 660 581 716 661 847 413 613 859 203 104 155 426 471 785 864 132 106 534 727 979 476 353 561 186 38 291 596 82...
output:
2 1 2 4 1 2 2 1 4 4 2 3 4 2 4 2 1 3 4 4 4 3 4 3 4 3 4 4 4 1 2 4 1 3 3 3 1 3 2 1 4 2 2 1 1 2 2 3 1 1 4 1 1 1 4 3 1 1 2 4 3 1 2 4 1 1 3 3 3 4 3 2 2 1 2 3 4 3 3 1 3 3 4 4 3 2 2 2 3 3 4 3 4 1 1 2 3 2 3 1 3 1 1 4 1 1 2 1 4 3 2 4 2 1 2 3 1 2 2 4 4 1 4 1 3 3 2 3 4 4 4 3 4 4 1 2 3 4 1 2 3 3 2 1 1 2 2 1 4 1 ...
result:
points 0.40 wrong 108 "ok" 4
Test #5:
score: 0
Wrong Answer
time: 460ms
memory: 35568kb
input:
5 4000 524 666 160 834 416 567 371 589 472 27 790 459 856 424 688 446 169 197 837 492 137 22 5 721 232 666 878 621 140 199 976 987 610 272 565 196 409 552 853 327 161 175 957 253 732 108 344 6 443 458 846 21 710 93 579 650 833 211 358 450 714 920 778 197 181 355 1000 87 395 180 800 763 69 553 74 887...
output:
3 4 3 3 2 3 1 4 3 3 2 3 4 4 3 3 2 4 3 2 2 2 1 2 2 2 3 4 4 3 4 4 3 2 3 3 2 4 3 4 4 2 1 3 4 4 2 2 3 1 4 4 3 4 1 2 4 2 4 3 1 1 4 4 1 2 1 2 1 1 3 3 4 4 1 4 2 4 4 1 1 1 3 2 3 2 1 3 1 2 1 2 1 4 1 2 3 2 1 4 2 1 1 4 1 1 1 3 4 3 2 2 4 4 2 4 2 3 4 3 4 2 1 1 1 4 4 2 1 2 2 1 1 1 2 4 1 1 2 3 2 2 4 3 2 3 3 1 3 4 ...
result:
points 0.0 wrong 106 "ok" 0