Submission #1131144
Source Code Expand
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) ((x < 0)?-(x):x) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector<int> A(N); for(int i =0; i < N; i++) cin >> A[i]; vector< vector<int> > G(N); for(int i =0; i < N-1; i++) { int a,b; cin >> a >> b; G[--a].push_back(--b); G[b].push_back(a);} vector<bool> live(N,true); vector<int> L; for(int i =0; i < N; i++) if(G[i].size() == 1) L.push_back(i); vector<int> S(N,0),D(N); vector< vector<int> > Sv(N); for(int i =0; i < N; i++) D[i] =G[i].size(); int n =L.size(); while(!L.empty()) { if(n == N) { if((int)L.size() == 2) { if(A[L[0]] == A[L[1]]) cout << "YES\n"; else cout << "NO\n";} else { if(A[L[0]] == 0) cout << "YES\n"; else cout << "NO\n";} return 0;} ALL_THE(L,it) live[*it] =false; vector<int> Ln; ALL_THE(L,it) { ALL_THE(G[*it],jt) { D[*jt]--; S[*jt] +=A[*it]; Sv[*jt].push_back(A[*it]); if(D[*jt] == 1 && live[*jt]) Ln.push_back(*jt);} } ALL_THE(Ln,it) { int a =S[*it]-A[*it], b =2*A[*it]-S[*it]; if(a < 0 || b < 0 || 2*a > S[*it]) { cout << "NO\n"; return 0;} sort(begin(Sv[*it]),end(Sv[*it])); if(a > S[*it]-Sv[*it].back()) { cout << "NO\n"; return 0;} A[*it] =b;} n +=Ln.size(); L =Ln;} cout << "YES\n"; return 0;} // look at my code // my code is amazing
Submission Info
Submission Time | |
---|---|
Task | C - Cleaning |
User | xellos |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2235 Byte |
Status | AC |
Exec Time | 73 ms |
Memory | 12796 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
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, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 68 ms | 12796 KB |
in10.txt | AC | 69 ms | 12796 KB |
in11.txt | AC | 64 ms | 12416 KB |
in12.txt | AC | 64 ms | 12416 KB |
in13.txt | AC | 61 ms | 12416 KB |
in14.txt | AC | 63 ms | 12416 KB |
in15.txt | AC | 1 ms | 256 KB |
in16.txt | AC | 1 ms | 256 KB |
in17.txt | AC | 1 ms | 256 KB |
in18.txt | AC | 1 ms | 256 KB |
in19.txt | AC | 55 ms | 11900 KB |
in2.txt | AC | 67 ms | 12796 KB |
in20.txt | AC | 49 ms | 10748 KB |
in21.txt | AC | 50 ms | 10876 KB |
in22.txt | AC | 55 ms | 11900 KB |
in23.txt | AC | 65 ms | 12668 KB |
in24.txt | AC | 50 ms | 10748 KB |
in25.txt | AC | 1 ms | 256 KB |
in26.txt | AC | 51 ms | 10748 KB |
in27.txt | AC | 51 ms | 10748 KB |
in28.txt | AC | 1 ms | 256 KB |
in29.txt | AC | 47 ms | 10748 KB |
in3.txt | AC | 69 ms | 12796 KB |
in30.txt | AC | 1 ms | 256 KB |
in31.txt | AC | 50 ms | 10748 KB |
in32.txt | AC | 50 ms | 10748 KB |
in33.txt | AC | 64 ms | 12796 KB |
in34.txt | AC | 64 ms | 12796 KB |
in35.txt | AC | 66 ms | 12668 KB |
in36.txt | AC | 65 ms | 12412 KB |
in37.txt | AC | 2 ms | 384 KB |
in38.txt | AC | 50 ms | 10748 KB |
in39.txt | AC | 50 ms | 10748 KB |
in4.txt | AC | 73 ms | 12796 KB |
in40.txt | AC | 49 ms | 10748 KB |
in41.txt | AC | 51 ms | 10876 KB |
in42.txt | AC | 68 ms | 12796 KB |
in43.txt | AC | 50 ms | 10748 KB |
in44.txt | AC | 59 ms | 12284 KB |
in45.txt | AC | 68 ms | 12796 KB |
in5.txt | AC | 66 ms | 12796 KB |
in6.txt | AC | 65 ms | 12796 KB |
in7.txt | AC | 60 ms | 11516 KB |
in8.txt | AC | 16 ms | 3200 KB |
in9.txt | AC | 64 ms | 12796 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |