結果
問題 | No.2563 色ごとのグループ |
ユーザー | SyimP |
提出日時 | 2023-12-02 16:58:54 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,249 bytes |
コンパイル時間 | 2,287 ms |
コンパイル使用メモリ | 190,384 KB |
実行使用メモリ | 23,936 KB |
最終ジャッジ日時 | 2024-09-26 20:57:54 |
合計ジャッジ時間 | 9,357 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | RE | - |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | WA | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | TLE | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
ソースコード
#include <bits/stdc++.h> #include <iomanip> #define rep(i,n) for (int i = (int)(0); i < (int)(n); i++) #define rep1(i,n) for (int i = (int)(1); i <= (int)(n); i++) #define REP(i,s,n) for (int i = (int)(s); i < (int)(n); i++) #define mrep(i,s,n) for (int i = (int)(s) - 1; i >= (int)(n); i--) #define fore(i,a) for(auto &i:a) #define all(c) begin(c), end(c) #define rall(x) x.rbegin(), x.rend() #define vcsort(x) sort(all(x)) #define rev(x) reverse(all(x)) #define vcerase(x) x.erase(unique(all(x)),x.end()) #define vcsum(x) accumulate(all(x),0) #define vcmax(x) *max_element(all(x)) #define vcmin(x) *min_element(all(x)) #define FI first #define SE second #define pb(x) push_back(x) #define ppb(x) pop_back(X) #define EL '\n' #define v(type, name, ...) vector<type> name(__VA_ARGS__) #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) //#define print(x) cout << x << "\n"; //----- using namespace std; using ll = long long; using Ul = unsigned long long; using cl = const ll; using VI = vector<int>; using VS = vector<string>; using VC = vector<char>; using VL = vector<ll>; using VB = vector<bool>; using PI = pair<int, int>; using PL = pair<ll, ll>; using SI = set<int>; using MII = map<int, int>; using MIS = map<int, string>; using MSI = map<string, int>; template<class t> using V = vector<t>; template< typename T > //vector<int> a(n); cin >> a; ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } //-tekito- int GCD(int a, int b) {if(b == 0){return a;}return GCD(b,a % b);}//最大公約数 int LCM(int a, int b) {return a/GCD(a, b)*b;}//最小公倍数 ll llsm1(ll n) { return (n * (n + 1)) / 2; }//1~nの総和 int kaijo(int n) {if(n==0||n==1){return 1;}else{return n*kaijo(n - 1);}}//階乗 int ketaSum(int num) {int digit_sum=0;while(num>0){digit_sum+=num%10;num/=10;}return digit_sum;}//各桁の和 string revstr(const string& str) {string reversed=str;reverse(reversed.begin(),reversed.end());return reversed;}//文字列反転 bool isPrime(int n) {if(n<2){return false;}for(int i=2;i*i<=n;i++){if(n%i==0){return false;}}return true;} int getNthPrime(int n) {std::vector<bool> isPrime(1e7, true);isPrime[0] = isPrime[1] = false;int count = 0; int prime = 2;while (count < n) {if (isPrime[prime]) {count++;if (count == n)break;for (int i = prime * 2; i < 1e7; i += prime)isPrime[i] = false;}prime++;}return prime;} long long ppow(int base, int exponent) {long long result=1;while(exponent>0){if(exponent%2==1){result*=base;}base*=base;exponent/=2;}return result;} char getAlp(int a) {if(a>0||a<27){return'A'+a-1;}} char getalp(int a) {if(a>0||a<27){return'a'+a-1;}} int getAlpin(char a) {if(a>='A'||a<='Z'){return a-64;}} int getalpin(char a) {if(a>='a'||a<='z'){return a-96;}} template<class t,class u> bool chmax(t&a,u b) {if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b) {if(b<a){a=b;return true;}else return false;} //-io- void fix(int a){cout << fixed << setprecision(a);} void ent() { cout << "\n";}//print() void OYN(bool a){cout << (a ? "YES" : "NO") << "\n";} void Oyn(bool a){cout << (a ? "Yes" : "No") << "\n";} void oyn(bool a){cout << (a ? "yes" : "no") << "\n";} const string YESNO[2] = {"NO", "YES"};//上 const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void print() { cout << '\n'; } template<typename T>//print(a,b,c,...) void print(const T &t) { cout << t << '\n'; } template<typename Head, typename... Tail> void print(const Head &head, const Tail &... tail) { cout << head << ' '; print(tail...); } //----- const int MOD = 998244353; //1+119×2^23 const int INF = 1e9+7; //-search- using Graph = vector<vector<int>>; int dx[8]={1,0,-1,0,1,1,-1,-1}; int dy[8]={0,-1,0,1,-1,1,1,-1}; /*↓↓↓ CODES ↓↓↓*/ /*cin してないやつは愚か*/ int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin >> n >> m; Graph g(n); set<int> st,cnc; rep(i,n){ st.insert(i); } map<int,int> mp; VI c(n); rep(i,n){ cin >> c[i]; mp[i] = c[i]; cnc.insert(c[i]); } VI cnt(cnc.size(),-1); rep(i,m){ int u,v; cin >> u >> v; g[u-1].pb(v-1); g[v-1].pb(u-1); } VI visited(n,0); queue<int> q; while(vcsum(visited) != n){ visited[*(st.begin())] = 1; q.push(*(st.begin())); int cr = c[*(st.begin())]; st.erase(*(st.begin())); bool jd = false; while(!q.empty()){ int v = q.front(); q.pop(); for(int it : g[v]){ if(c[it] != c[v] || visited[it] == 1)continue; else jd = true; visited[it] = 1; q.push(it); st.erase(it); } } cnt[mp[cr]]++; } cout << vcsum(cnt); }