/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 2ms 320.0 KiB
#4 Accepted 2ms 324.0 KiB
#5 Accepted 26ms 1.25 MiB
#6 Accepted 27ms 1.371 MiB
#7 Accepted 342ms 9.055 MiB
#8 Accepted 361ms 9.133 MiB
#9 Accepted 364ms 9.133 MiB
#10 Accepted 181ms 7.098 MiB

Code


#include <vector>
#include <numeric>
#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<pair<int, int>> moves = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int tt;
  cin >> tt;
  for (int tc = 1; tc <= tt; tc++) {
    cout << "Case " << tc << ":";
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      e[u].push_back(v);
      e[v].push_back(u);
    }
    vector<int> b(n);
    for (int i = 0; i < q; i++) {
      int x;
      cin >> x;
      b[x - 1] ^= 1;
    }
    vector<int> que(1, 0), par(n, -1);
    for (int i = 0; i < (int) que.size(); i++) {
      int v = que[i];
      a[v] ^= b[v];
      for (int u : e[v]) {
        if (u != par[v]) {
          par[u] = v;
          b[u] ^= b[v];
          que.push_back(u);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      cout << ' ' << a[i];
    }
    cout << '\n';
  }
  return 0;
}
 

Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 20:33:35
Judged At
2024-11-11 03:31:28
Judged By
Score
100
Total Time
364ms
Peak Memory
9.133 MiB