Submission #19282356


Source Code Expand

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

#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 ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int A[202020],B[202020],D[202020];
int C[101];
int E[101][101];
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<101> uf;


void dfs(int cur) {
	int i;
	FOR(i,N) if(C[cur]==C[i]&&E[cur][i]>=0&&D[E[cur][i]]==-1) {
		int x=E[cur][i];
		if(A[x]==cur) D[x]=0;
		else D[x]=1;
		dfs(i);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	MINUS(D);
	MINUS(E);
	cin>>N>>M;
	FOR(i,M) {
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
		E[A[i]][B[i]]=i;
		E[B[i]][A[i]]=i;
	}
	FOR(i,N) cin>>C[i];
	FOR(i,M) {
		if(C[A[i]]>C[B[i]]) D[i]=0;
		if(C[A[i]]<C[B[i]]) D[i]=1;
		if(C[A[i]]==C[B[i]]) uf(A[i],B[i]);
	}
	
	FOR(i,N) if(uf[i]==i) dfs(i);
	
	
	FOR(i,M) {
		if(D[i]==0) cout<<"->"<<endl;
		else cout<<"<-"<<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 D - Orientation
User kmjp
Language C++ (GCC 9.2.1)
Score 600
Code Size 2105 Byte
Status AC
Exec Time 21 ms
Memory 4756 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:48:8: warning: unused variable ‘j’ [-Wunused-variable]
   48 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:48:10: warning: unused variable ‘k’ [-Wunused-variable]
   48 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:48:12: warning: unused variable ‘l’ [-Wunused-variable]
   48 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:48:14: warning: unused variable ‘r’ [-Wunused-variable]
   48 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:48:16: warning: unused variable ‘x’ [-Wunused-variable]
   48 |  int i,j,k,l,r,x,y; string s;
      |                ^
./Main.cpp:48:18: warning: unused variable ‘y’ [-Wunused-variable]
   48 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:81:38: note: in expansion of macro ‘FOR’
   81 |  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 600 / 600
Status AC
AC × 52
Set Name Test Cases
Sample
All cycle_00, cycle_01, cycle_02, cycle_tree_00, cycle_tree_01, cycle_tree_02, example_00, example_01, example_02, many_small_00, many_small_01, many_small_02, many_small_03, many_small_04, many_small_05, many_small_06, many_small_07, many_small_08, many_small_09, many_small_10, many_small_11, many_small_12, many_small_13, many_small_14, many_small_15, many_small_16, many_small_17, many_small_18, many_small_19, max_random_00, max_random_01, max_random_02, max_random_03, max_random_04, max_random_05, max_random_06, max_random_07, max_random_08, max_random_09, perfect_00, perfect_01, perfect_02, small_00, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09
Case Name Status Exec Time Memory
cycle_00 AC 8 ms 4448 KB
cycle_01 AC 3 ms 4460 KB
cycle_02 AC 10 ms 4448 KB
cycle_tree_00 AC 2 ms 4464 KB
cycle_tree_01 AC 3 ms 4448 KB
cycle_tree_02 AC 3 ms 4348 KB
example_00 AC 3 ms 4456 KB
example_01 AC 2 ms 4336 KB
example_02 AC 2 ms 4304 KB
many_small_00 AC 3 ms 4444 KB
many_small_01 AC 3 ms 4340 KB
many_small_02 AC 4 ms 4420 KB
many_small_03 AC 4 ms 4356 KB
many_small_04 AC 7 ms 4456 KB
many_small_05 AC 3 ms 4348 KB
many_small_06 AC 4 ms 4456 KB
many_small_07 AC 4 ms 4468 KB
many_small_08 AC 5 ms 4488 KB
many_small_09 AC 4 ms 4428 KB
many_small_10 AC 6 ms 4496 KB
many_small_11 AC 5 ms 4488 KB
many_small_12 AC 4 ms 4396 KB
many_small_13 AC 5 ms 4420 KB
many_small_14 AC 4 ms 4348 KB
many_small_15 AC 3 ms 4460 KB
many_small_16 AC 5 ms 4348 KB
many_small_17 AC 4 ms 4408 KB
many_small_18 AC 5 ms 4416 KB
many_small_19 AC 9 ms 4504 KB
max_random_00 AC 3 ms 4316 KB
max_random_01 AC 3 ms 4448 KB
max_random_02 AC 6 ms 4448 KB
max_random_03 AC 7 ms 4464 KB
max_random_04 AC 3 ms 4404 KB
max_random_05 AC 9 ms 4504 KB
max_random_06 AC 3 ms 4392 KB
max_random_07 AC 5 ms 4468 KB
max_random_08 AC 7 ms 4380 KB
max_random_09 AC 6 ms 4560 KB
perfect_00 AC 20 ms 4736 KB
perfect_01 AC 18 ms 4756 KB
perfect_02 AC 21 ms 4756 KB
small_00 AC 4 ms 4424 KB
small_01 AC 2 ms 4412 KB
small_02 AC 2 ms 4444 KB
small_03 AC 2 ms 4456 KB
small_04 AC 2 ms 4428 KB
small_05 AC 2 ms 4356 KB
small_06 AC 2 ms 4340 KB
small_07 AC 3 ms 4456 KB
small_08 AC 2 ms 4448 KB
small_09 AC 2 ms 4408 KB