提出 #47238486


ソースコード 拡げる

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200100; // 2*(10^5)
vvec G(nmax);

int n,m;

vector<int> color(nmax,-1);

void dfs(int now, int pre){
  int nowc = color[now];
  for(auto next: G[now]){
    if(pre==next) continue;
    if(color[next]==-1){
      color[next] = (nowc+1)%2;
      dfs(next, now);
    }
    else if(color[next]==nowc){
      cout << "No" << endl;

      exit(0);
    }
  }
}

void solve4ts()
{
  
  cin >> n>> m;
  vector<int> aa(m), bb(m);
  rep(i,m) cin >> aa[i];
  rep(i,m) cin >> bb[i];

  rep(i,m){
    int a = aa[i];
    int b = bb[i];
    a--;
    b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  rep(i,n){
    if(color[i]==-1){
      color[i]=0;
      dfs(i, -1);
    }
  }
  cout << "Yes" << endl;
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
  int repeat = 1;
  // cin >> repeat;
  while(repeat--) solve4ts();
}

/*

g++ -std=c++1z code.cpp

./a.out

python3 expander.py code.cpp

*/

提出情報

提出日時
問題 D - Good Tuple Problem
ユーザ yotsutose
言語 C++ 23 (gcc 12.2)
得点 400
コード長 3006 Byte
結果 AC
実行時間 53 ms
メモリ 28160 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 27
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_1_00.txt, 01_random_1_01.txt, 01_random_1_02.txt, 01_random_1_03.txt, 01_random_1_04.txt, 02_random_2_00.txt, 02_random_2_01.txt, 02_random_2_02.txt, 02_random_2_03.txt, 02_random_2_04.txt, 02_random_2_05.txt, 02_random_2_06.txt, 02_random_2_07.txt, 02_random_2_08.txt, 02_random_2_09.txt, 03_tree_00.txt, 04_path_00.txt, 05_corner_00.txt, 05_corner_01.txt, 05_corner_02.txt, 05_corner_03.txt, 05_corner_04.txt, 05_corner_05.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 4 ms 9348 KiB
00_sample_01.txt AC 4 ms 9184 KiB
00_sample_02.txt AC 3 ms 9252 KiB
00_sample_03.txt AC 3 ms 9204 KiB
01_random_1_00.txt AC 9 ms 10664 KiB
01_random_1_01.txt AC 7 ms 9908 KiB
01_random_1_02.txt AC 10 ms 10796 KiB
01_random_1_03.txt AC 10 ms 10800 KiB
01_random_1_04.txt AC 21 ms 13804 KiB
02_random_2_00.txt AC 14 ms 13644 KiB
02_random_2_01.txt AC 17 ms 15600 KiB
02_random_2_02.txt AC 13 ms 13332 KiB
02_random_2_03.txt AC 15 ms 14160 KiB
02_random_2_04.txt AC 14 ms 13296 KiB
02_random_2_05.txt AC 13 ms 13656 KiB
02_random_2_06.txt AC 17 ms 15672 KiB
02_random_2_07.txt AC 19 ms 16200 KiB
02_random_2_08.txt AC 15 ms 15144 KiB
02_random_2_09.txt AC 19 ms 16400 KiB
03_tree_00.txt AC 46 ms 19924 KiB
04_path_00.txt AC 38 ms 28080 KiB
05_corner_00.txt AC 3 ms 9248 KiB
05_corner_01.txt AC 19 ms 16660 KiB
05_corner_02.txt AC 18 ms 15840 KiB
05_corner_03.txt AC 18 ms 15936 KiB
05_corner_04.txt AC 36 ms 28160 KiB
05_corner_05.txt AC 53 ms 26568 KiB