結果

問題 No.1023 Cyclic Tour
ユーザー LayCurseLayCurse
提出日時 2020-04-10 23:02:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,177 bytes
コンパイル時間 3,308 ms
コンパイル使用メモリ 219,484 KB
実行使用メモリ 26,832 KB
最終ジャッジ日時 2023-10-14 04:11:36
合計ジャッジ時間 15,572 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,488 KB
testcase_01 AC 3 ms
9,744 KB
testcase_02 AC 3 ms
9,484 KB
testcase_03 AC 3 ms
9,520 KB
testcase_04 AC 56 ms
19,472 KB
testcase_05 AC 57 ms
19,524 KB
testcase_06 AC 62 ms
20,332 KB
testcase_07 AC 55 ms
19,780 KB
testcase_08 AC 102 ms
19,600 KB
testcase_09 AC 99 ms
19,612 KB
testcase_10 AC 97 ms
19,448 KB
testcase_11 WA -
testcase_12 AC 99 ms
19,748 KB
testcase_13 AC 94 ms
19,404 KB
testcase_14 AC 85 ms
14,808 KB
testcase_15 AC 100 ms
19,592 KB
testcase_16 AC 130 ms
16,604 KB
testcase_17 AC 239 ms
24,100 KB
testcase_18 AC 119 ms
16,524 KB
testcase_19 AC 91 ms
15,272 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 280 ms
24,328 KB
testcase_26 AC 292 ms
24,644 KB
testcase_27 AC 273 ms
24,168 KB
testcase_28 AC 295 ms
24,500 KB
testcase_29 AC 262 ms
24,332 KB
testcase_30 AC 301 ms
24,704 KB
testcase_31 AC 259 ms
24,240 KB
testcase_32 AC 287 ms
24,048 KB
testcase_33 AC 302 ms
24,532 KB
testcase_34 AC 287 ms
24,068 KB
testcase_35 AC 294 ms
24,496 KB
testcase_36 WA -
testcase_37 AC 278 ms
24,852 KB
testcase_38 AC 269 ms
24,376 KB
testcase_39 WA -
testcase_40 AC 276 ms
24,116 KB
testcase_41 AC 292 ms
24,164 KB
testcase_42 AC 305 ms
24,756 KB
testcase_43 AC 82 ms
14,904 KB
testcase_44 AC 69 ms
19,668 KB
testcase_45 AC 73 ms
23,000 KB
testcase_46 AC 76 ms
23,016 KB
testcase_47 AC 61 ms
23,012 KB
testcase_48 WA -
testcase_49 AC 274 ms
26,832 KB
testcase_50 WA -
testcase_51 AC 188 ms
26,524 KB
testcase_52 AC 220 ms
26,424 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 ind, int b = -1){
  int Lj4PdHRW;
  if(vis[n]){
    return 0;
  }
  vis[n] = ind;
  for(Lj4PdHRW=(0);Lj4PdHRW<(g.es[n]);Lj4PdHRW++){
    auto &i = g.edge[n][Lj4PdHRW];
    if(i==b){
      continue;
    }
    if(vis[i]==ind){
      return 1;
    }
    if(solve(i, ind, n)){
      return 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, i+1)){
        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 ind, int b = -1){
//   if(vis[n]) return 0;
//   vis[n] = ind;
//   rep[g.edge[n]](i,g.es[n]){
//     if(i==b) continue;
//     if(vis[i]==ind) return 1;
//     if(solve(i, ind, n)) return 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, i+1)) wt("Yes"), return 0;
//   wt("No");
// }
0