Submission #17617055
Source Code Expand
// __________________
// | ________________ |
// || ____ ||
// || /\ | ||
// || /__\ | ||
// || / \ |____ ||
// ||________________||
// |__________________|
// \###################\
// \###################\
// \ ____ \
// \_______\___\_______\
// An AC a day keeps the doctor away.
#ifdef local
#include <bits/extc++.h>
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(args...) qqbx(#args, args)
using ost = std::ostream;
#define DESTL(STL, BEG, END, OUT) \
template <typename ...T> ost& operator<<(ost &O, std::STL<T...> v) { int f=0; for(auto x: v) O << (f++ ? ", " : BEG) << OUT; return O << END; }
DESTL(deque, "[", "]", x); DESTL(vector, "[", "]", x);
DESTL(set, "{", "}", x); DESTL(multiset, "{", "}", x); DESTL(unordered_set, "{", "}", x);
DESTL(map , "{", "}", x.first << ":" << x.second); DESTL(unordered_map , "{", "}", x.first << ":" << x.second);
template <typename U, typename V> ost& operator<<(ost &O, std::pair<U,V> p) { return O << '(' << p.first << ',' << p.second << ')'; }
template <typename T, size_t N> ost& operator<<(ost &O, std::array<T,N> a) { int f=0; for(T x: a) O << (f++ ? ", " : "[") << x; return O << "]"; }
template <typename T, size_t ...I> ost& prtuple(ost &O, T t, std::index_sequence<I...>) { return (..., (O << (I ? ", " : "(") << std::get<I>(t))), O << ")"; }
template <typename ...T> ost& operator<<(ost &O, std::tuple<T...> t) { return prtuple(O, t, std::make_index_sequence<sizeof...(T)>()); }
template <typename ...T> void qqbx(const char *s, T ...args) {
int cnt = sizeof...(T);
(std::cerr << "\033[1;32m(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)
using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 2000025, INF = 1e18, MOD = 1000000007, K = 19, inf = 1e7;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }
ll sum[N];
int pa[N], rk[N];
int anc(int x) { return x==pa[x] ? x : pa[x]=anc(pa[x]); }
bool join(int x, int y) {
if((x=anc(x)) == (y=anc(y))) return false;
if(rk[x] < rk[y]) swap(x, y);
return pa[y] = x, sum[x] += sum[y], rk[x]!=rk[y] || ++rk[x];
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) pa[i] = i;
for(int i = 1, x; i <= n; i++) cin >> x, sum[i] += x;
for(int i = 1, x; i <= n; i++) cin >> x, sum[i] -= x;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
join(a, b);
}
for(int i = 1; i <= n; i++) if(sum[anc(i)] != 0) return cout << "No\n", 0;
cout << "Yes\n";
}
Submission Info
| Submission Time |
|
| Task |
B - Values |
| User |
bingxuan9112 |
| Language |
C++ (GCC 9.2.1) |
| Score |
400 |
| Code Size |
3748 Byte |
| Status |
AC |
| Exec Time |
81 ms |
| Memory |
6736 KiB |
Compile Error
./Main.cpp:9:1: warning: multi-line comment [-Wcomment]
9 | // \###################\
| ^
./Main.cpp:35: warning: ignoring #pragma loop_opt [-Wunknown-pragmas]
35 | #pragma loop_opt(on)
|
./Main.cpp: In function ‘constexpr ll cdiv(ll, ll)’:
./Main.cpp:60:56: warning: suggest parentheses around comparison in operand of ‘^’ [-Wparentheses]
60 | constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
| ~^~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03 |
| All |
00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03, 01_small_0, 01_small_1, 01_small_2, 01_small_3, 01_small_4, 01_small_5, 01_small_6, 01_small_7, 01_small_8, 01_small_9, 02_large_0, 02_large_1, 02_largecon_0, 02_largecon_1, 02_largecon_2, 02_largecon_3, 02_largecon_4, 02_largecon_5, 02_toolarge_0, 02_toolarge_1, 02_toolarge_2, 02_toolarge_3, 03_few_e_0, 03_few_e_1, 03_few_e_2, 03_few_e_3, 03_few_e_4, 03_few_e_5, 03_is_tree_0, 03_is_tree_1, 03_is_tree_2, 03_is_tree_3, 04_kill_overflow_0, 04_kill_overflow_1, 04_kill_overflow_2, 04_kill_overflow_3, 04_sumequal_0, 04_sumequal_1, 04_sumequal_2, 04_sumequal_3 |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00 |
AC |
16 ms |
3608 KiB |
| 00_sample_01 |
AC |
2 ms |
3536 KiB |
| 00_sample_02 |
AC |
2 ms |
3616 KiB |
| 00_sample_03 |
AC |
3 ms |
3544 KiB |
| 01_small_0 |
AC |
2 ms |
3644 KiB |
| 01_small_1 |
AC |
2 ms |
3532 KiB |
| 01_small_2 |
AC |
2 ms |
3480 KiB |
| 01_small_3 |
AC |
4 ms |
3492 KiB |
| 01_small_4 |
AC |
4 ms |
3612 KiB |
| 01_small_5 |
AC |
2 ms |
3520 KiB |
| 01_small_6 |
AC |
5 ms |
3520 KiB |
| 01_small_7 |
AC |
2 ms |
3644 KiB |
| 01_small_8 |
AC |
2 ms |
3608 KiB |
| 01_small_9 |
AC |
3 ms |
3568 KiB |
| 02_large_0 |
AC |
55 ms |
5696 KiB |
| 02_large_1 |
AC |
26 ms |
4416 KiB |
| 02_largecon_0 |
AC |
69 ms |
5740 KiB |
| 02_largecon_1 |
AC |
71 ms |
6048 KiB |
| 02_largecon_2 |
AC |
68 ms |
5848 KiB |
| 02_largecon_3 |
AC |
51 ms |
5148 KiB |
| 02_largecon_4 |
AC |
76 ms |
6264 KiB |
| 02_largecon_5 |
AC |
66 ms |
5420 KiB |
| 02_toolarge_0 |
AC |
81 ms |
6696 KiB |
| 02_toolarge_1 |
AC |
79 ms |
6668 KiB |
| 02_toolarge_2 |
AC |
74 ms |
6608 KiB |
| 02_toolarge_3 |
AC |
77 ms |
6736 KiB |
| 03_few_e_0 |
AC |
36 ms |
4964 KiB |
| 03_few_e_1 |
AC |
44 ms |
5572 KiB |
| 03_few_e_2 |
AC |
40 ms |
5132 KiB |
| 03_few_e_3 |
AC |
45 ms |
5612 KiB |
| 03_few_e_4 |
AC |
43 ms |
5576 KiB |
| 03_few_e_5 |
AC |
41 ms |
5396 KiB |
| 03_is_tree_0 |
AC |
55 ms |
5652 KiB |
| 03_is_tree_1 |
AC |
54 ms |
5448 KiB |
| 03_is_tree_2 |
AC |
51 ms |
5220 KiB |
| 03_is_tree_3 |
AC |
51 ms |
5256 KiB |
| 04_kill_overflow_0 |
AC |
74 ms |
6076 KiB |
| 04_kill_overflow_1 |
AC |
56 ms |
5252 KiB |
| 04_kill_overflow_2 |
AC |
58 ms |
5296 KiB |
| 04_kill_overflow_3 |
AC |
56 ms |
5128 KiB |
| 04_sumequal_0 |
AC |
43 ms |
5484 KiB |
| 04_sumequal_1 |
AC |
32 ms |
4472 KiB |
| 04_sumequal_2 |
AC |
16 ms |
4212 KiB |
| 04_sumequal_3 |
AC |
33 ms |
4696 KiB |