Thuật toán:
Code:
/* Coder : Nguyen Duc Tam */ #include<iostream> #include<cstdio> #include<algorithm> #include<set> #include<vector> #include<utility> #include<map> #include<list> #include<queue> #include<stack> #include<cstring> #include<string> #include<cmath> #include<cstdlib> using namespace std; #define REP(i, start, end, step) for(int i = start; i < end; i += step) #define DOWN(i, start, end, step) for(int i = start; i > end; i -= step) #define FOR(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) #define X first #define Y second #define L(x,i) ((x) << (i)) #define R(x,i) ((x) >> (i)) #define AND(a,b) ((a) & (b)) #define OR(a,b) ((a) | (b)) #define XOR(a,b) ((a) ^ (b)) #define NOT(a) (~(a)) #define SB(x,i) (OR((x), L(1, (i)))) // x | 1 << i #define CB(x,i) (AND((x),NOT(L(1,(i))))) // x & ~(1 << i) #define TB(x,i) (AND((x), L(1,(i)))) // x & (1 << i) #define FILL(a,val) memset(a,val,sizeof(a)); #define INIT(a,l,r,val) REP(i,l,r,1) (a)[i] = val; #define DIG(c) (int)((c) - '0') #define CHR(c) (char)((c) + '0') #define LOW(c) (char)((c) + 32) #define UPP(c) (char)((c) - 32) #define EPS 1e-7 #define OO 1000000005 #define N 100005 const int DAY[13] = {-1,31,29,31,30,31,30,31,31,30,31,30,31}; typedef pair<int,int> II; typedef pair<II,int> D; typedef long long LL; typedef unsigned long long ULL; typedef unsigned char UC; int n,m,c[N],a,b,deg[N],ca,cb; set<int> q[N]; int ans, number = 0; int main() { #define Off false if(Off) { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); } cin >> n >> m; REP(i,0,n,1) scanf("%d",&c[i]); REP(i,0,m,1) { scanf("%d %d",&a,&b); ca = c[--a]; cb = c[--b]; if(ca != cb && q[ca].find(cb) == q[ca].end()) { q[ca].insert(cb); q[cb].insert(ca); deg[ca]++; deg[cb]++; } } ans = c[0]; REP(i,1,n,1) { if(deg[c[i]] > number) { number = deg[c[i]]; ans = c[i]; } if(number == deg[c[i]] && ans > c[i]) { ans = c[i]; } } cout << ans << endl; return 0; }
Không có nhận xét nào:
Đăng nhận xét