Submission #17627624


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<202020> uf;
int N,M;
ll X[202020];
vector<int> E[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>X[i];
	FOR(i,N) {
		cin>>x;
		X[i]-=x;
	}
	FOR(i,M) {
		cin>>x>>y;
		uf(x-1,y-1);
	}
	
	FOR(i,N) if(uf[i]!=i) {
		X[uf[i]]+=X[i];
		X[i]=0;
	}
	if(count(X,X+N,0)==N) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task B - Values
User kmjp
Language C++ (GCC 9.2.1)
Score 400
Code Size 1698 Byte
Status AC
Exec Time 93 ms
Memory 11876 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:36:8: warning: unused variable ‘j’ [-Wunused-variable]
   36 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:36:10: warning: unused variable ‘k’ [-Wunused-variable]
   36 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:36:12: warning: unused variable ‘l’ [-Wunused-variable]
   36 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:36:14: warning: unused variable ‘r’ [-Wunused-variable]
   36 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:7:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:66:38: note: in expansion of macro ‘FOR’
   66 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 44
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 12 ms 10116 KB
00_sample_01 AC 9 ms 10100 KB
00_sample_02 AC 11 ms 9992 KB
00_sample_03 AC 9 ms 10032 KB
01_small_0 AC 9 ms 10100 KB
01_small_1 AC 12 ms 10036 KB
01_small_2 AC 10 ms 9968 KB
01_small_3 AC 9 ms 10148 KB
01_small_4 AC 14 ms 9992 KB
01_small_5 AC 11 ms 10112 KB
01_small_6 AC 9 ms 10096 KB
01_small_7 AC 16 ms 10072 KB
01_small_8 AC 9 ms 10124 KB
01_small_9 AC 9 ms 10036 KB
02_large_0 AC 54 ms 11260 KB
02_large_1 AC 37 ms 10748 KB
02_largecon_0 AC 79 ms 11276 KB
02_largecon_1 AC 80 ms 11552 KB
02_largecon_2 AC 79 ms 11208 KB
02_largecon_3 AC 57 ms 11084 KB
02_largecon_4 AC 88 ms 11584 KB
02_largecon_5 AC 74 ms 11208 KB
02_toolarge_0 AC 89 ms 11736 KB
02_toolarge_1 AC 91 ms 11800 KB
02_toolarge_2 AC 86 ms 11876 KB
02_toolarge_3 AC 93 ms 11800 KB
03_few_e_0 AC 39 ms 11292 KB
03_few_e_1 AC 48 ms 11552 KB
03_few_e_2 AC 44 ms 11256 KB
03_few_e_3 AC 47 ms 11612 KB
03_few_e_4 AC 48 ms 11536 KB
03_few_e_5 AC 44 ms 11612 KB
03_is_tree_0 AC 64 ms 11204 KB
03_is_tree_1 AC 61 ms 11272 KB
03_is_tree_2 AC 56 ms 11028 KB
03_is_tree_3 AC 60 ms 11008 KB
04_kill_overflow_0 AC 84 ms 11564 KB
04_kill_overflow_1 AC 63 ms 10988 KB
04_kill_overflow_2 AC 71 ms 10988 KB
04_kill_overflow_3 AC 66 ms 11008 KB
04_sumequal_0 AC 48 ms 11304 KB
04_sumequal_1 AC 39 ms 10772 KB
04_sumequal_2 AC 20 ms 10480 KB
04_sumequal_3 AC 36 ms 10820 KB