Submission #1096916
Source Code Expand
//#define USEPB_DS
#define USETR1
#define CPPELEVEN
#define GPP
/*
* temp.cpp
*
* Created on: 2012-7-18
* Author: BSBandme
*/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <list>
#include <iomanip>
#include <math.h>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <tuple>
using namespace std;
#ifndef CPPELEVEN
#ifdef USETR1
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#endif
#else
#include <unordered_map>
#include <unordered_set>
#endif
#ifdef USEPB_DS
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag
typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq_type;
// splay_tree_tag, ov_tree_tag
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tree_type;
#endif
#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <double, double> pdd;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <double> vd;
typedef vector <string> vs;
typedef map <string, int> mpsi;
typedef map <double, int> mpdi;
typedef map <int, int> mpii;
const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};
template <class T> inline T abs1(T a) {return a < 0 ? -a : a;}
#ifndef CPPELEVEN
template <class T> inline T max1(T a, T b) { return b < a ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }
#else
template <typename t, typename t1>
t min1(t a, t1 b) { return a < b ? a : b; }
template <typename t, typename... arg>
t min1(t a, arg... arr) { return min1(a, min1(arr...)); }
template <typename t, typename t1>
t max1(t a, t1 b) { return a > b ? a : b; }
template <typename t, typename... arg>
t max1(t a, arg... arr) { return max1(a, max1(arr...)); }
#endif
inline int jud(double a, double b){
if(abs(a) < eps && abs(b) < eps) return 0;
else if(abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;
if(a < b) return -1;
return 1;
}
template <typename t> inline int jud(t a, t b){
if(a < b) return -1;
if(a == b) return 0;
return 1;
}
// f_lb == 1代表返回相同的一串的左边界,f_small == 1代表返回如果没有寻找的值返回小的数
template <typename it, typename t1>
inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1){
if(na == 0) return 0;
int be = 0, en = na - 1;
if(*a <= *(a + na - 1)){
if(f_lb == 0) while(be < en){
int mid = (be + en + 1) / 2;
if(jud(*(a + mid), val) != 1) be = mid;
else en = mid - 1;
}else while(be < en){
int mid = (be + en) / 2;
if(jud(*(a + mid), val) != -1) en = mid;
else be = mid + 1;
}
if(f_small && jud(*(a + be), val) == 1) be--;
if(!f_small && jud(*(a + be), val) == -1) be++;
} else {
if(f_lb) while(be < en){
int mid = (be + en + 1) / 2;
if(jud(*(a + mid), val) != -1) be = mid;
else en = mid - 1;
}else while(be < en){
int mid = (be + en) / 2;
if(jud(*(a + mid), val) != 1) en = mid;
else be = mid + 1;
}
if(!f_small && jud(*(a + be), val) == -1) be--;
if(f_small && jud(*(a + be), val) == 1) be++;
}
return be;
}
template <class T> inline T lowb(T num) {return num & (-num); }
#ifdef GPP
inline int bitnum(ui nValue) { return __builtin_popcount(nValue); }
inline int bitnum(int nValue) { return __builtin_popcount(nValue); }
inline int bitnum(ull nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitnum(ll nValue) { return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32); }
inline int bitmaxl(ui a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(int a) { if(a == 0) return 0; return 32 - __builtin_clz(a); }
inline int bitmaxl(ull a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
inline int bitmaxl(ll a) { int temp = a >> 32; if(temp) return 32 - __builtin_clz(temp) + 32; return bitmaxl(int(a)); }
#else
#endif
long long pow(long long n, long long m, long long mod = 0){
if(m < 0) return 0;
long long ans = 1;
long long k = n;
while(m){
if(m & 1) {
ans *= k;
if(mod) ans %= mod;
}
k *= k;
if(mod) k %= mod;
m >>= 1;
}
return ans;
}
#define MOD 1000000007
template <class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
if(mod == -1) mod = MOD;
a += b;
while(a >= mod) a -= mod;
while(a < 0) a += mod;
}
template <class t>
void output1(t arr) {
for(int i = 0; i < (int)arr.size(); i++)
cerr << arr[i] << ' ';
cerr << endl;
}
template <class t>
void output2(t arr) {
for(int i = 0; i < (int)arr.size(); i++)
output1(arr[i]);
}
//....................密..........封..........线..........下..........禁..........止..........hack...............................................
const int maxn = 3010;
int n;
vi e[maxn];
int arr[maxn];
int dp[maxn];
int main() {
//............................不要再忘了检查maxn大小了!!!!BSBandme你个SB!!!!...................................................
ios_base::sync_with_stdio(0);
#ifdef DEBUG //......................................................................................................
freopen("input.txt", "r", stdin);
int __size__ = 256 << 20; // 256MB
char *__p__ = (char*)malloc(__size__) + __size__;
__asm__("movl %0, %%esp\n" :: "r"(__p__));
#endif //...........................................................................................................
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d", arr + i);
for(int i = 0; i < n - 1; i++) {
int a, b;
scanf("%d%d", &a, &b);
a--; b--;
e[a].push_back(b);
e[b].push_back(a);
}
bool have = 1;
while(have) {
have = 0;
for(int i = 0; i < n; i++) if(dp[i] == 0){
have = 1;
bool flag = 1;
for(auto it : e[i]) if(dp[it] == 0 && arr[it] < arr[i]){
flag = 0;
break;
}
if(flag) {
dp[i] = -1;
for(auto it : e[i]) if(arr[it] > arr[i])
dp[it] = 1;
}
}
}
for(int i = 0; i < n; i++) if(dp[i] == 1)
printf("%d ", i + 1);
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Tree Game |
User |
BSBandme |
Language |
C++14 (GCC 5.4.1) |
Score |
1600 |
Code Size |
7448 Byte |
Status |
AC |
Exec Time |
4 ms |
Memory |
512 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:221:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:223:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", arr + i);
^
./Main.cpp:226:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
^
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 |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
AC |
4 ms |
512 KB |
in10.txt |
AC |
4 ms |
512 KB |
in11.txt |
AC |
4 ms |
512 KB |
in12.txt |
AC |
3 ms |
384 KB |
in13.txt |
AC |
3 ms |
384 KB |
in14.txt |
AC |
4 ms |
512 KB |
in15.txt |
AC |
4 ms |
512 KB |
in16.txt |
AC |
4 ms |
512 KB |
in17.txt |
AC |
4 ms |
512 KB |
in18.txt |
AC |
4 ms |
512 KB |
in19.txt |
AC |
4 ms |
512 KB |
in2.txt |
AC |
4 ms |
512 KB |
in20.txt |
AC |
4 ms |
512 KB |
in21.txt |
AC |
4 ms |
512 KB |
in22.txt |
AC |
4 ms |
512 KB |
in23.txt |
AC |
4 ms |
512 KB |
in24.txt |
AC |
4 ms |
512 KB |
in25.txt |
AC |
4 ms |
512 KB |
in26.txt |
AC |
4 ms |
512 KB |
in27.txt |
AC |
4 ms |
512 KB |
in28.txt |
AC |
4 ms |
512 KB |
in29.txt |
AC |
4 ms |
512 KB |
in3.txt |
AC |
4 ms |
512 KB |
in30.txt |
AC |
4 ms |
512 KB |
in31.txt |
AC |
4 ms |
512 KB |
in32.txt |
AC |
4 ms |
512 KB |
in33.txt |
AC |
4 ms |
512 KB |
in34.txt |
AC |
4 ms |
512 KB |
in35.txt |
AC |
4 ms |
512 KB |
in36.txt |
AC |
3 ms |
384 KB |
in37.txt |
AC |
3 ms |
384 KB |
in38.txt |
AC |
2 ms |
384 KB |
in39.txt |
AC |
3 ms |
384 KB |
in4.txt |
AC |
4 ms |
512 KB |
in40.txt |
AC |
4 ms |
512 KB |
in41.txt |
AC |
4 ms |
512 KB |
in42.txt |
AC |
4 ms |
512 KB |
in43.txt |
AC |
4 ms |
512 KB |
in44.txt |
AC |
4 ms |
512 KB |
in45.txt |
AC |
4 ms |
384 KB |
in46.txt |
AC |
4 ms |
384 KB |
in47.txt |
AC |
4 ms |
512 KB |
in48.txt |
AC |
4 ms |
512 KB |
in49.txt |
AC |
4 ms |
512 KB |
in5.txt |
AC |
4 ms |
384 KB |
in50.txt |
AC |
4 ms |
512 KB |
in6.txt |
AC |
4 ms |
512 KB |
in7.txt |
AC |
4 ms |
512 KB |
in8.txt |
AC |
4 ms |
512 KB |
in9.txt |
AC |
4 ms |
512 KB |
sample1.txt |
AC |
3 ms |
384 KB |
sample2.txt |
AC |
3 ms |
384 KB |
sample3.txt |
AC |
3 ms |
384 KB |