QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410592#6662. 기지 간소화nguyentunglam0 14ms17500kbC++171.9kb2024-05-14 10:13:342024-05-14 10:13:35

Judging History

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

  • [2024-05-14 10:13:35]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:17500kb
  • [2024-05-14 10:13:34]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 3e5 + 10;

int st[N], ed[N], rev_st[N], dd[N], cnt[2], sz[N], cost[N];

vector<pair<int, int> > adj[N];

int timer, n;

long long ans;

void prep (int u, int p) {
//  cout << u << endl;
  st[u] = ++timer;
  rev_st[timer] = u;
  sz[u] = 1;
  for(auto &[v, c] : adj[u]) if (v != p) {
    cost[v] = c;
    prep(v, u);
    sz[u] += sz[v];
  }
  ed[u] = timer;
}

void dfs(int u, int p) {
  int heavy = 0;
//  cout << u << endl;
  for(auto &[v, w] : adj[u]) if (v != p && sz[v] > sz[heavy]) heavy = v;
  for(auto &[v, w] : adj[u]) if (v != p && v != heavy) {
    dfs(v, u);
    for(int j = st[v]; j <= ed[v]; j++) {
      dd[rev_st[j]] = 0;
//      if (u == 2) cout << rev_st[j] << endl;
    }
  }
  if (heavy) dfs(heavy, u);
  dd[u] = 1;
  for(auto &[v, w] : adj[u]) if (v != p && v != heavy) {
    for(int j = st[v]; j <= ed[v]; j++) dd[rev_st[j]] = 1;
  }
//  if (u == 2) {
//    for(int i = 0; i < n; i++) cout << dd[i] << " "; cout << endl;
//    cout << u << endl;
////  }
  for(int l = 0; l < n; l++) {
    cnt[0] = cnt[1] = 0;
    for(int r = l; r < n; r++) {
      cnt[dd[r]] = 1;
      if (cnt[0] && cnt[1]) {
        ans += cost[u];
//        cout << l << " " << r << " " << u << " " << cost[u] << endl;
      }
    }
  }
}

int maintenance_costs_sum (vector<int> U, vector<int> V, vector<int> W) {
  n = U.size() + 1;
  for(int i = 0; i < n - 1; i++) {
    adj[U[i]].emplace_back(V[i], W[i]);
    adj[V[i]].emplace_back(U[i], W[i]);
  }

  prep(0, 0);

  dfs(0, 0);

  return ans;
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

  int tot = maintenance_costs_sum({0, 2, 2, 0}, {2, 1, 4, 3}, {2, 1, 1, 1});
  cout << tot << endl;
}
#endif // ngu


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 16420kb

input:

2
1 0 1

output:

1

result:

ok single line: '1'

Test #2:

score: -5
Wrong Answer
time: 14ms
memory: 17500kb

input:

299
72 263 662908099
170 230 583287081
181 87 461245480
117 116 41098264
282 218 300936390
238 128 561969086
175 105 305200697
152 28 927649982
211 58 290232523
233 188 304617152
246 74 61325892
283 120 724838352
207 94 123021801
138 241 893659708
171 283 82846115
104 250 142703714
111 63 547249068
...

output:

1721042624

result:

wrong answer 1st lines differ - expected: '93964028', found: '1721042624'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #36:

score: 0
Time Limit Exceeded

input:

249494
137621 137622 1
198127 198128 1
117358 117359 1
155777 155778 1
112742 112743 1
235668 235669 1
20632 20622 1
41333 41334 1
170699 170692 1
130269 130268 1
137208 137207 1
37791 37767 1
130187 130178 1
89795 89817 1
91408 91359 1
243301 243574 1
22017 22018 1
116466 116467 1
160094 160095 1
4...

output:

Unauthorized output

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #48:

score: 0
Time Limit Exceeded

input:

249876
133760 107716 545485826
57898 35556 542825636
159559 78814 588304799
9037 105623 735470824
242676 240955 258616989
58653 143501 194781066
36591 97835 699376285
95049 123298 35300031
91751 203920 865003045
53908 18382 376452723
211462 200538 638209824
48693 89388 132147210
238496 151742 322726...

output:

Unauthorized output

result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%