QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#788625 | #114. Construction of Highway | _8_8_# | 0 | 0ms | 3560kb | C++23 | 1.1kb | 2024-11-27 17:42:26 | 2024-11-27 17:42:32 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)1e5 + 12, MOD = (int)1e9 + 7;
int n, pr[N], c[N], sum = 0;
void test() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
for(int i = 1; i <= n - 1; i++) {
int a, b;
cin >> a >> b;
pr[b] = a;
vector<int> x;
set<int> st;
while(a) {
x.push_back(a);
st.insert(c[a]);
a = pr[a];
}
sum += (int)st.size();
reverse(x.begin(), x.end());
int res = 0, m = (int)x.size();
for(int j = 0; j < m; j++) {
for(int k = j + 1; k < m; k++) {
if(c[x[j]] > c[x[k]]) {
res++;
}
}
}
for(int j : x) {
c[j] = c[b];
}
cout << res << '\n';
}
assert(sum <= n * 2);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 7
Accepted
time: 0ms
memory: 3560kb
input:
2 804289384 846930887 1 2
output:
0
result:
ok single line: '0'
Test #2:
score: 7
Accepted
time: 0ms
memory: 3556kb
input:
10 505335291 738766720 190686789 260874576 747983062 906156499 502820865 142559278 261608746 380759628 1 3 1 5 5 7 3 8 1 4 3 10 7 6 5 9 5 2
output:
0 0 0 1 0 1 0 0 0
result:
ok 9 lines
Test #3:
score: 0
Runtime Error
input:
100 205554747 483147986 844158169 953350441 612121426 310914941 210224073 856883377 922860802 495649265 8614859 989089925 378651394 344681740 29100603 816952842 21468265 552076976 87517202 953369896 374612516 787097143 126313439 207815259 287632274 886964648 220723886 119448938 444268469 865680799 6...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%