QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#558820#8220. 众生之门Fido_Puppy0 3ms6060kbC++233.9kb2024-09-11 18:42:582024-09-11 18:42:58

Judging History

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

  • [2024-09-11 18:42:58]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:6060kb
  • [2024-09-11 18:42:58]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define rz resize
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e4 + 7, Inf = 0x3f3f3f3f;
int n, s, t, dfn[N], dep[N], lis[N], fa[N], timer, ans[N];
vi G[N];
#define Bit(x) (31 - __builtin_clz(x))
struct SparseTable {
  int arr[16][N];
  void init() {
    For(i, 1, n) arr[0][i] = lis[i];
    For(i, 1, Bit(n)) For(j, 1, n - (1 << i) + 1) {
      arr[i][j] = dep[arr[i - 1][j]] <= dep[arr[i - 1][j + (1 << i - 1)]]? arr[i - 1][j] : arr[i - 1][j + (1 << i - 1)];
    }
  }
  int qry(int l, int r) {
    int t = Bit(r - l + 1);
    return dep[arr[t][l]] <= dep[arr[t][r - (1 << t) + 1]]? arr[t][l] : arr[t][r - (1 << t) + 1];
  }
} A;
void dfs(int u) {
  dep[u] = dep[fa[u]] + 1, lis[dfn[u] = ++timer] = u;
  for (int v : G[u]) {
    if (v == fa[u]) continue;
    fa[v] = u, dfs(v);
  }
}
int lca(int u, int v) {
  if (u == v) return u;
  if ((u = dfn[u]) > (v = dfn[v])) swap(u, v);
  return fa[A.qry(u + 1, v)];
}
int dist(int u, int v) {
  return dep[u] + dep[v] - dep[lca(u, v)] * 2;
}
namespace BruteForce {
  int p[N], mi;
  void main() {
    if (n == 2) {
      ans[1] = s, ans[2] = t;
      return ;
    }
    mi = Inf;
    int cur = 0;
    For(i, 1, n) if (i != s && i != t) p[++cur] = i;
    do {
      int w = dist(s, p[1]) ^ dist(p[n - 2], t);
      For(i, 1, n - 3) w ^= dist(p[i], p[i + 1]);
      if (w < mi) {
        mi = w;
        ans[1] = s, ans[n] = t;
        For(i, 2, n - 1) ans[i] = p[i - 1];
      }
    } while (next_permutation(p + 1, p + n - 1));
  }
}
namespace Chrysanthemum {
  void main() {
    ans[1] = s, ans[n] = t;
    int cur = 1;
    For(i, 2, n - 1) {
      while (cur == s || cur == t) ++cur;
      ans[i] = cur;
    }
  }
}
namespace Random {
  int p[N];
  void main() {
    int cur = 1;
    For(i, 1, n) if (i != s && i != t) p[++cur] = i;
    shuffle(p + 2, p + n, rnd);
    p[1] = s, p[n] = t;
    int w = 0;
    For(i, 1, n - 1) w ^= dist(p[i], p[i + 1]);
    while (w > 1) {
      int x, y;
      do {
        x = rnd() % (n - 2) + 2, y = rnd() % (n - 2) + 2;
      } while (x == y);
      if (x > y) swap(x, y);
      if (x == y - 1) {
        w ^= dist(p[x - 1], p[x]) ^ dist(p[y], p[y + 1]);
        swap(p[x], p[y]);
        w ^= dist(p[x - 1], p[x]) ^ dist(p[y], p[y + 1]);
      } else {
        w ^= dist(p[x - 1], p[x]) ^ dist(p[x], p[x + 1]) ^ dist(p[y - 1], p[y]) ^ dist(p[y], p[y + 1]);
        swap(p[x], p[y]);
        w ^= dist(p[x - 1], p[x]) ^ dist(p[x], p[x + 1]) ^ dist(p[y - 1], p[y]) ^ dist(p[y], p[y + 1]);
      }
    }
    For(i, 1, n) ans[i] = p[i];
  }
}
void Main() {
  cin >> n >> s >> t;
  For(i, 1, n) G[i].clear();
  For(i, 1, n - 1) {
    int u, v; cin >> u >> v, G[u].pb(v), G[v].pb(u);
  }
  dfs(1), A.init();
  int mx = 0;
  For(i, 1, n) mx = max(mx, (int)(G[i].size()));
  if (n <= 9) BruteForce::main();
  else if (mx == n - 1) Chrysanthemum::main();
  else Random::main();
  For(i, 1, n) cout << ans[i] << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int t; cin >> t;
  while (t--) Main();
  cerr << (double)(clock()) / CLOCKS_PER_SEC << '\n';
  return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5984kb

input:

114
6 5 6
2 6
1 6
4 5
3 1
6 4
6 3 6
2 4
4 1
6 4
1 5
5 3
6 6 1
5 2
1 2
4 6
2 4
3 2
6 6 1
3 6
5 3
1 6
4 2
2 5
6 3 1
5 3
2 4
1 5
4 3
6 3
4 3 4
2 3
1 4
4 3
6 3 1
2 3
6 3
4 3
1 6
5 1
5 3 2
1 2
4 2
2 3
5 2
6 1 4
2 1
5 2
4 1
6 2
3 6
6 5 1
4 2
6 5
1 3
2 6
3 2
4 4 1
2 4
3 4
1 4
6 2 5
3 5
4 6
1 4
6 2
5 4
6 1 ...

output:

5 1 2 3 4 6 
3 1 4 5 2 6 
6 3 4 5 2 1 
6 2 3 5 4 1 
3 4 2 6 5 1 
3 2 1 4 
3 2 5 4 6 1 
3 1 4 5 2 
1 2 3 5 6 4 
5 4 6 2 3 1 
4 2 3 1 
2 1 4 3 6 5 
1 5 2 6 4 3 
3 2 4 6 5 1 
2 3 1 6 5 4 
3 2 5 6 1 4 
5 1 4 2 6 3 
1 3 2 4 5 
4 1 3 2 
3 1 5 2 4 
1 2 3 4 
3 4 1 2 
5 3 1 4 2 
5 2 4 3 1 
5 4 1 2 6 3 
4 1 6...

result:

wrong answer Your solution is worse than Jury's in test case 3. Yours:3 Jury's:1

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

14190
43 27 2
42 3
30 36
11 24
21 22
13 8
22 30
31 29
35 1
10 6
2 23
28 17
2 26
7 37
5 19
38 43
33 39
4 28
33 7
25 31
15 1
32 18
34 27
35 12
19 32
20 17
37 42
26 34
39 10
12 27
24 43
18 6
16 9
38 9
14 15
14 41
25 3
40 13
16 8
36 41
20 5
21 40
11 29
41 24 38
21 6
20 14
26 1
6 7
17 16
39 36
8 18
36 11...

output:

27 38 6 17 43 25 12 33 35 14 15 21 20 4 36 10 28 41 23 42 19 32 34 18 24 30 37 5 8 29 3 40 11 31 9 39 13 7 22 16 1 26 2 
24 20 12 22 15 33 31 40 23 39 25 2 7 14 35 1 4 26 18 19 13 10 41 34 27 6 29 32 37 36 21 16 28 30 17 5 8 11 9 3 38 
5 2 19 3 8 4 26 9 24 15 18 12 10 13 20 23 11 27 17 1 7 14 21 16 ...

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #18:

score: 0
Time Limit Exceeded

input:

32752
15 3 4
14 12
4 12
1 10
9 13
7 6
12 5
1 12
9 15
7 9
8 12
2 6
11 6
9 3
6 10
13 12 2
10 11
10 5
1 4
12 11
4 6
2 13
6 5
9 6
8 13
6 3
4 8
13 7
15 3 6
15 10
4 2
8 5
10 3
1 3
15 2
8 4
12 9
7 8
11 8
6 13
8 12
14 8
6 12
15 5 7
8 14
10 13
11 13
13 5
2 14
15 8
15 1
6 2
7 15
9 13
15 3
6 13
15 4
12 5
15 10...

output:

3 12 9 8 6 1 5 15 10 11 13 14 2 7 4 
12 4 7 3 11 5 9 6 13 8 1 10 2 
3 13 9 14 15 8 5 7 2 11 12 10 1 4 6 
5 14 1 12 13 15 10 9 6 8 4 11 3 2 7 
10 3 2 9 5 1 15 14 13 7 11 6 4 12 8 
11 7 9 2 6 1 4 8 5 10 3 
11 15 8 3 2 12 1 5 6 14 13 4 7 10 9 
14 8 1 6 7 10 2 11 3 9 4 5 13 12 
5 7 1 4 11 8 6 2 9 10 3 
...

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #25:

score: 0
Time Limit Exceeded

input:

36059
13 9 4
5 9
10 3
3 1
13 5
12 5
7 4
2 8
8 10
4 9
11 7
6 11
1 4
13 12 6
4 12
13 9
11 2
6 12
9 12
8 5
7 6
5 3
3 7
10 8
1 5
2 10
13 10 8
3 1
5 9
4 8
6 11
7 13
13 5
1 10
12 13
9 4
11 9
2 11
8 10
12 1 4
9 2
2 12
3 2
12 11
8 2
7 4
5 1
4 1
11 7
10 9
6 9
13 10 12
7 5
11 9
12 10
9 8
3 10
8 5
4 13
13 7
6 ...

output:

9 6 3 13 11 2 10 8 1 12 5 7 4 
12 9 7 1 13 2 3 8 5 10 11 4 6 
10 7 1 11 9 6 12 2 13 3 4 5 8 
1 7 11 5 8 10 12 2 3 6 9 4 
10 8 13 5 1 4 2 11 6 3 9 7 12 
6 10 2 11 3 7 1 13 9 12 4 5 8 
1 12 5 6 7 2 3 4 11 10 9 13 8 
7 9 5 4 8 6 1 10 2 3 
11 6 9 4 7 12 2 13 8 5 3 10 1 
4 7 9 12 1 2 10 11 8 13 3 5 6 
6 ...

result:


Subtask #6:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 3ms
memory: 6060kb

input:

10
1000 165 244
175 661
738 362
280 462
776 922
231 578
963 615
639 836
32 418
519 220
565 733
239 951
768 847
196 200
246 119
591 288
994 586
313 46
971 515
512 811
228 908
627 339
33 337
447 488
616 319
399 727
921 615
421 509
167 354
905 382
20 356
875 414
619 904
824 940
435 244
953 663
719 962
...

output:

165 665 640 379 780 360 39 473 652 302 340 820 625 962 330 555 144 986 630 678 288 939 318 711 493 593 879 656 386 96 220 362 333 918 963 197 396 44 73 287 212 549 577 661 265 757 893 51 364 821 504 158 342 383 17 435 491 463 852 18 92 891 935 182 434 599 862 336 858 368 695 813 251 789 489 138 204 ...

result:

wrong answer Your solution is worse than Jury's in test case 2. Yours:43 Jury's:1

Subtask #7:

score: 0
Skipped

Dependency #2:

0%