标签:
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 252 Accepted Submission(s): 74
7 3 30 350 100 200 300 400 1 2 2 3 3 4 4 5 5 6 6 7
5
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <fstream> #include <string> #include <time.h> #include <vector> #include <map> #include <queue> #include <algorithm> #include <stack> #include <cstring> #include <cmath> #include <set> #include <vector> using namespace std; template <class T> inline bool rd(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c<'0' || c>'9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return 1; } template <class T> inline void pt(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) pt(x / 10); putchar(x % 10 + '0'); } typedef long long ll; typedef pair<int, int> pii; const int N = 500000 + 10; int n; vector<int>G[N]; pii a[N]; int w[N], r[N]; int main() { while (cin>>n) { for (int i = 1; i <= n; i++) { G[i].clear(); rd(a[i].first); a[i].second = i; w[i] = a[i].first; } for (int i = 1, u, v; i < n; i++) { rd(u); rd(v); G[u].push_back(v); G[v].push_back(u); } sort(a + 1, a + 1 + n); int ans = 1; for (int i = n; i; i--) { int id = a[i].second; int tmp = 1; for (auto v : G[id]) { if (w[id] > w[v])continue; tmp += r[v]; } r[id] = tmp; ans = max(ans, tmp); } pt(ans); puts(""); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq574857122/article/details/47110737