結果

問題 No.1023 Cyclic Tour
ユーザー LayCurseLayCurse
提出日時 2020-04-10 22:51:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,162 bytes
コンパイル時間 3,525 ms
コンパイル使用メモリ 218,236 KB
実行使用メモリ 26,856 KB
最終ジャッジ日時 2023-10-14 03:41:10
合計ジャッジ時間 14,822 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,460 KB
testcase_01 AC 3 ms
9,548 KB
testcase_02 AC 3 ms
9,468 KB
testcase_03 AC 3 ms
9,484 KB
testcase_04 AC 55 ms
19,580 KB
testcase_05 AC 55 ms
19,680 KB
testcase_06 AC 68 ms
20,192 KB
testcase_07 AC 60 ms
19,880 KB
testcase_08 AC 112 ms
19,568 KB
testcase_09 AC 108 ms
19,424 KB
testcase_10 AC 103 ms
19,300 KB
testcase_11 AC 119 ms
19,936 KB
testcase_12 AC 102 ms
19,636 KB
testcase_13 AC 92 ms
19,372 KB
testcase_14 AC 83 ms
14,880 KB
testcase_15 AC 100 ms
19,580 KB
testcase_16 AC 130 ms
16,612 KB
testcase_17 AC 249 ms
24,300 KB
testcase_18 AC 118 ms
16,340 KB
testcase_19 AC 91 ms
15,348 KB
testcase_20 AC 294 ms
24,380 KB
testcase_21 AC 280 ms
24,412 KB
testcase_22 AC 279 ms
24,196 KB
testcase_23 AC 298 ms
24,524 KB
testcase_24 AC 286 ms
24,724 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 271 ms
24,704 KB
testcase_28 AC 300 ms
24,544 KB
testcase_29 AC 266 ms
24,308 KB
testcase_30 AC 299 ms
24,752 KB
testcase_31 AC 265 ms
24,528 KB
testcase_32 AC 276 ms
26,416 KB
testcase_33 WA -
testcase_34 AC 265 ms
24,220 KB
testcase_35 AC 274 ms
24,548 KB
testcase_36 AC 281 ms
24,316 KB
testcase_37 AC 278 ms
25,540 KB
testcase_38 AC 268 ms
24,784 KB
testcase_39 AC 296 ms
24,356 KB
testcase_40 AC 274 ms
24,340 KB
testcase_41 AC 293 ms
24,352 KB
testcase_42 WA -
testcase_43 AC 81 ms
14,748 KB
testcase_44 WA -
testcase_45 AC 76 ms
25,892 KB
testcase_46 AC 75 ms
25,892 KB
testcase_47 AC 64 ms
25,888 KB
testcase_48 AC 207 ms
26,772 KB
testcase_49 AC 253 ms
26,856 KB
testcase_50 AC 195 ms
26,852 KB
testcase_51 AC 182 ms
26,856 KB
testcase_52 AC 228 ms
26,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  a[k] = aval;
  b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  for(i=sz-1;i>k;i--){
    d[i] = d[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
  d[k] = dval;
}
struct graph{
  int N;
  int *es;
  int **edge;
  void setDirectEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    walloc1d(&edge[0], M, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
    }
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      edge[A[i]][es[A[i]]++] = B[i];
    }
  }
}
;
int N;
int M;
int A[400000];
int B[400000];
int C[400000];
graph g;
int vis[100000];
int solve(int n, int b = -1){
  int Lj4PdHRW;
  if(vis[n]){
    return 0;
  }
  vis[n] = 2;
  for(Lj4PdHRW=(0);Lj4PdHRW<(g.es[n]);Lj4PdHRW++){
    auto &i = g.edge[n][Lj4PdHRW];
    if(i==b){
      continue;
    }
    if(vis[i]==2){
      return 1;
    }
    if(solve(i, n)){
      return 1;
    }
  }
  vis[n] = 1;
  return 0;
}
int main(){
  int i;
  wmem = memarr;
  set<pair<int,int>> s0;
  set<pair<int,int>> s1;
  rd(N);
  rd(M);
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(M);e98WHCEY++){
      rd(A[e98WHCEY]);A[e98WHCEY] += (-1);
      rd(B[e98WHCEY]);B[e98WHCEY] += (-1);
      rd(C[e98WHCEY]);C[e98WHCEY] += (-1);
    }
  }
  for(i=(0);i<(M);i++){
    if(C[i]==0){
      s0.insert( make_pair(A[i], B[i]) );
      if(s1.count(make_pair(A[i], B[i]))){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
      if(s1.count(make_pair(B[i], A[i]))){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
    }
    else{
      s1.insert( make_pair(A[i], B[i]) );
      if(s0.count(make_pair(A[i], B[i]))){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
      if(s0.count(make_pair(B[i], A[i]))){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
      if(s1.count(make_pair(B[i], A[i]))){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
    }
  }
  int WYIGIcGE = M;
  for(i=(0);i<(WYIGIcGE);i++){
    if(C[i]==0){
      arrInsert(M,M,A,B[i],B,A[i]);
    }
  }
  g.setDirectEdge(N,M,A,B);
  for(i=(0);i<(N);i++){
    if(!vis[i]){
      if(solve(i)){
        wt_L("Yes");
        wt_L('\n');
        return 0;
      }
    }
  }
  wt_L("No");
  wt_L('\n');
  return 0;
}
// cLay varsion 20200408-1

// --- original code ---
// int N, M, A[4d5], B[4d5], C[4d5];
// graph g;
// 
// int vis[1d5];
// int solve(int n, int b = -1){
//   if(vis[n]) return 0;
//   vis[n] = 2;
//   rep[g.edge[n]](i,g.es[n]){
//     if(i==b) continue;
//     if(vis[i]==2) return 1;
//     if(solve(i, n)) return 1;
//   }
//   vis[n] = 1;
//   return 0;
// }
// 
// {
//   set<pair<int,int>> s0, s1;
//   rd(N,M,(A--,B--,C--)(M));
// 
//   rep(i,M){
//     if(C[i]==0){
//       s0.insert( make_pair(A[i], B[i]) );
//       if(s1.count(make_pair(A[i], B[i]))) wt("Yes"), return 0;
//       if(s1.count(make_pair(B[i], A[i]))) wt("Yes"), return 0;
//     } else {
//       s1.insert( make_pair(A[i], B[i]) );
//       if(s0.count(make_pair(A[i], B[i]))) wt("Yes"), return 0;
//       if(s0.count(make_pair(B[i], A[i]))) wt("Yes"), return 0;
//       if(s1.count(make_pair(B[i], A[i]))) wt("Yes"), return 0;
//     }
//   }
// 
//   REP(i,M) if(C[i]==0) arrInsert(M,M,A,B[i],B,A[i]);
//   g.setDirectEdge(N,M,A,B);
//   rep(i,N) if(!vis[i]) if(solve(i)) wt("Yes"), return 0;
//   wt("No");
// }
0