# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
486428 | blue | Construction of Highway (JOI18_construction) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;
cin >> N;
int C[1+N];
for(int i = 1; i <= N; i++) cin >> C[i];
int P[1+N];
P[0] = P[1] = 0;
for(int j = 1; j <= N-1; j++)
{
vector<int> lst;
int A, B;
cin >> A >> B;
for(int q = A; q != 0; q = P[q])
lst.push_back(C[q]);
reverse(lst.begin(), lst.end());
int ans = 0;
for(int i = 0; i < int(lst.size()); i++)
for(int j = i+1; j < int(lst.size()); j++)
ans += lst[i] > lst[j];
cout << ans << '\n';
for(int k = A; k != 0; k = P[k])
C[k] = C[B];
P[B] = A;
}
}