Submission #1734887
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define For(i , j , k) for (register int i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i) #define Fordown(i , j , k) for (register int i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i) #define Set(a , b) memset(a , b , sizeof(a)) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define ALL(a) (a).begin(), (a).end() #define SZ(a) ((int)(a).size()) #define INF (0x3f3f3f3f) #define INF1 (2139062143) #define Mod (1000000007) typedef long long LL; template <typename T> inline bool chkmax(T &a , T b) { return a < b ? (a = b , 1) : 0; } template <typename T> inline bool chkmin(T &a , T b) { return b < a ? (a = b , 1) : 0; } int _ , __; char c_; inline int read() { for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1; for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48); return _ * __; } inline void File() { #ifdef hany01 freopen("tree_game.in" , "r" , stdin); freopen("tree_game.out" , "w" , stdout); #endif } const int maxn = 3010; int n, a[maxn], v[maxn << 1], nex[maxn << 1], beg[maxn], dp[maxn], e; inline void add(int uu, int vv) { v[++ e] = vv; nex[e] = beg[uu]; beg[uu] = e; } inline void Init() { int uu, vv; n = read(); For(i, 1, n) a[i] = read(); For(i, 2, n) uu = read(), vv = read(), add(uu, vv), add(vv, uu); } void dfs1(int u, int fa) { for (int i = beg[u] ; i ; i = nex[i]) { if (fa == v[i]) continue; dfs1(v[i], u); if (!dp[v[i]] && a[u] > a[v[i]]) dp[u] = 1; } } void dfs2(int u, int fa) { if (u != 1 && !dp[fa] && a[u] > a[fa]) dp[u] = 1; for (int i = beg[u] ; i ; i = nex[i]) if (v[i] != fa) dfs2(v[i], u); } int main() { File(); Init(); dfs1(1, 0); dfs2(1, 0); For(i, 1, n) if (dp[i]) printf("%d ", i); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Tree Game |
User | Hany01 |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 1867 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 512 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1600 / 1600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in5.txt, in50.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 2 ms | 384 KB |
in10.txt | AC | 2 ms | 384 KB |
in11.txt | AC | 2 ms | 384 KB |
in12.txt | AC | 1 ms | 256 KB |
in13.txt | AC | 2 ms | 256 KB |
in14.txt | AC | 2 ms | 384 KB |
in15.txt | AC | 2 ms | 384 KB |
in16.txt | AC | 2 ms | 384 KB |
in17.txt | AC | 2 ms | 384 KB |
in18.txt | AC | 2 ms | 384 KB |
in19.txt | AC | 2 ms | 384 KB |
in2.txt | AC | 2 ms | 384 KB |
in20.txt | AC | 2 ms | 384 KB |
in21.txt | AC | 2 ms | 512 KB |
in22.txt | AC | 2 ms | 384 KB |
in23.txt | AC | 2 ms | 384 KB |
in24.txt | AC | 2 ms | 512 KB |
in25.txt | AC | 2 ms | 384 KB |
in26.txt | AC | 2 ms | 512 KB |
in27.txt | AC | 2 ms | 384 KB |
in28.txt | AC | 2 ms | 384 KB |
in29.txt | AC | 2 ms | 384 KB |
in3.txt | AC | 2 ms | 384 KB |
in30.txt | AC | 2 ms | 384 KB |
in31.txt | AC | 2 ms | 384 KB |
in32.txt | AC | 2 ms | 384 KB |
in33.txt | AC | 2 ms | 384 KB |
in34.txt | AC | 2 ms | 384 KB |
in35.txt | AC | 2 ms | 384 KB |
in36.txt | AC | 1 ms | 256 KB |
in37.txt | AC | 1 ms | 256 KB |
in38.txt | AC | 1 ms | 256 KB |
in39.txt | AC | 1 ms | 256 KB |
in4.txt | AC | 2 ms | 384 KB |
in40.txt | AC | 2 ms | 384 KB |
in41.txt | AC | 2 ms | 384 KB |
in42.txt | AC | 2 ms | 384 KB |
in43.txt | AC | 2 ms | 384 KB |
in44.txt | AC | 2 ms | 384 KB |
in45.txt | AC | 2 ms | 256 KB |
in46.txt | AC | 2 ms | 256 KB |
in47.txt | AC | 2 ms | 384 KB |
in48.txt | AC | 2 ms | 384 KB |
in49.txt | AC | 2 ms | 384 KB |
in5.txt | AC | 2 ms | 256 KB |
in50.txt | AC | 2 ms | 384 KB |
in6.txt | AC | 2 ms | 384 KB |
in7.txt | AC | 2 ms | 384 KB |
in8.txt | AC | 2 ms | 384 KB |
in9.txt | AC | 2 ms | 384 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |