結果

問題 No.364 門松木
ユーザー ryofjt
提出日時 2016-09-12 18:17:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,173 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 53,100 KB
最終ジャッジ日時 2024-11-14 19:49:39
合計ジャッジ時間 2,359 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:9:9: error: ‘vector’ does not name a type
    9 | typedef vector<int> V;
      |         ^~~~~~
main.cpp:10:9: error: ‘vector’ does not name a type
   10 | typedef vector<short> VS;
      |         ^~~~~~
main.cpp:11:9: error: ‘vector’ does not name a type
   11 | typedef vector<uint> VU;
      |         ^~~~~~
main.cpp:15:1: error: ‘V’ does not name a type
   15 | V t[50000];
      | ^
main.cpp:19:1: error: ‘VU’ does not name a type
   19 | VU eval(const VS& c, const VU& v, int p){
      | ^~
main.cpp: In function ‘uint dfs(int, int)’:
main.cpp:34:9: error: ‘VS’ was not declared in this scope
   34 |         VS c(1000, 0);
      |         ^~
main.cpp:35:9: error: ‘VU’ was not declared in this scope
   35 |         VU v(1000, 0);
      |         ^~
main.cpp:36:20: error: ‘t’ was not declared in this scope
   36 |         for(int i: t[x]){
      |                    ^
main.cpp:38:25: error: ‘c’ was not declared in this scope
   38 |                         c[a[i]] = 1;
      |                         ^
main.cpp:39:25: error: ‘v’ was not declared in this scope
   39 |                         v[a[i]] = max(dfs(i, a[x]), v[a[i]]);
      |                         ^
main.cpp:42:24: error: ‘c’ was not declared in this scope
   42 |         auto e1 = eval(c, v, a[x]);
      |                        ^
main.cpp:42:27: error: ‘v’ was not declared in this scope
   42 |         auto e1 = eval(c, v, a[x]);
      |                           ^
main.cpp:42:19: error: ‘eval’ was not declared in this scope
   42 |         auto e1 = eval(c, v, a[x]);
      |                   ^~~~
main.cpp: In function ‘int main()’:
main.cpp:61:17: error: ‘t’ was not declared in this scope
   61 |                 t[x].push_back(y);
      |                 ^

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef unsigned int uint;
typedef vector<int> V;
typedef vector<short> VS;
typedef vector<uint> VU;
int n;
int a[50000];
V t[50000];
bool u[50000];
uint ans;
VU eval(const VS& c, const VU& v, int p){
V cs(1000 + 1, 0);
VU vs(1000 + 1, 0);
rep(i, 1000){
cs[i + 1] = cs[i] + c[i];
vs[i + 1] = vs[i] + v[i];
}
uint ca = cs[p], va = vs[p];
uint cb = cs[1000] - cs[p + 1], vb = vs[1000] - vs[p + 1];
uint vc = vs[p + 1] - vs[p];
return {ca * (ca - 1) / 2 + va, cb * (cb - 1) / 2 + vb, vc};
}
uint dfs(int x, int k){
u[x] = true;
VS c(1000, 0);
VU v(1000, 0);
for(int i: t[x]){
if(!u[i]){
c[a[i]] = 1;
v[a[i]] = max(dfs(i, a[x]), v[a[i]]);
}
}
auto e1 = eval(c, v, a[x]);
ans = max(*max_element(e1.begin(), e1.end()), ans);
c[k] = 1;
v[k] = 0;
auto e2 = eval(c, v, a[x]);
return x[a] != k ? e2[x[a] < k] : e2[2];
}
int main(){
cin >> n;
rep(i, n){
cin >> a[i];
--a[i];
}
rep(i, n - 1){
int x, y;
cin >> x >> y;
--x;
--y;
t[x].push_back(y);
t[y].push_back(x);
}
dfs(0, 1);
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0