結果

問題 No.1254 補強への架け橋
ユーザー LayCurseLayCurse
提出日時 2020-10-09 21:50:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 4,714 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 218,288 KB
実行使用メモリ 18,044 KB
最終ジャッジ日時 2023-09-27 16:25:44
合計ジャッジ時間 10,276 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,564 KB
testcase_01 AC 2 ms
5,576 KB
testcase_02 AC 1 ms
5,428 KB
testcase_03 AC 2 ms
5,428 KB
testcase_04 AC 2 ms
5,524 KB
testcase_05 AC 2 ms
5,512 KB
testcase_06 AC 2 ms
5,448 KB
testcase_07 AC 2 ms
5,496 KB
testcase_08 AC 2 ms
5,424 KB
testcase_09 AC 2 ms
5,568 KB
testcase_10 AC 1 ms
5,608 KB
testcase_11 AC 2 ms
5,572 KB
testcase_12 AC 2 ms
5,448 KB
testcase_13 AC 1 ms
5,364 KB
testcase_14 AC 1 ms
5,640 KB
testcase_15 AC 2 ms
5,568 KB
testcase_16 AC 2 ms
5,452 KB
testcase_17 AC 1 ms
5,424 KB
testcase_18 AC 1 ms
5,444 KB
testcase_19 AC 1 ms
5,484 KB
testcase_20 AC 2 ms
5,340 KB
testcase_21 AC 2 ms
5,572 KB
testcase_22 AC 2 ms
5,344 KB
testcase_23 AC 2 ms
5,492 KB
testcase_24 AC 1 ms
5,592 KB
testcase_25 AC 2 ms
5,572 KB
testcase_26 AC 1 ms
5,340 KB
testcase_27 AC 2 ms
5,424 KB
testcase_28 AC 2 ms
5,336 KB
testcase_29 AC 2 ms
5,396 KB
testcase_30 AC 1 ms
5,364 KB
testcase_31 AC 2 ms
5,500 KB
testcase_32 AC 2 ms
5,564 KB
testcase_33 AC 2 ms
5,444 KB
testcase_34 AC 1 ms
5,620 KB
testcase_35 AC 2 ms
5,464 KB
testcase_36 AC 2 ms
5,340 KB
testcase_37 AC 2 ms
5,364 KB
testcase_38 AC 1 ms
5,336 KB
testcase_39 AC 1 ms
5,336 KB
testcase_40 AC 2 ms
5,352 KB
testcase_41 AC 1 ms
5,568 KB
testcase_42 AC 2 ms
5,348 KB
testcase_43 AC 1 ms
5,452 KB
testcase_44 AC 2 ms
5,500 KB
testcase_45 AC 1 ms
5,344 KB
testcase_46 AC 2 ms
5,364 KB
testcase_47 AC 2 ms
5,512 KB
testcase_48 AC 2 ms
5,404 KB
testcase_49 AC 2 ms
5,440 KB
testcase_50 AC 2 ms
5,528 KB
testcase_51 AC 1 ms
5,360 KB
testcase_52 AC 2 ms
5,604 KB
testcase_53 AC 2 ms
5,592 KB
testcase_54 AC 2 ms
5,448 KB
testcase_55 AC 1 ms
5,440 KB
testcase_56 AC 1 ms
5,356 KB
testcase_57 AC 2 ms
5,380 KB
testcase_58 AC 2 ms
5,456 KB
testcase_59 AC 2 ms
5,504 KB
testcase_60 AC 2 ms
5,452 KB
testcase_61 AC 2 ms
5,656 KB
testcase_62 AC 2 ms
5,364 KB
testcase_63 AC 3 ms
5,600 KB
testcase_64 AC 2 ms
5,496 KB
testcase_65 AC 2 ms
5,572 KB
testcase_66 AC 2 ms
5,652 KB
testcase_67 AC 2 ms
5,736 KB
testcase_68 AC 2 ms
5,556 KB
testcase_69 AC 2 ms
5,588 KB
testcase_70 AC 3 ms
5,656 KB
testcase_71 AC 2 ms
5,496 KB
testcase_72 AC 3 ms
5,520 KB
testcase_73 AC 3 ms
5,412 KB
testcase_74 AC 2 ms
5,484 KB
testcase_75 AC 3 ms
5,548 KB
testcase_76 AC 2 ms
5,388 KB
testcase_77 AC 2 ms
5,532 KB
testcase_78 AC 3 ms
5,624 KB
testcase_79 AC 3 ms
5,632 KB
testcase_80 AC 3 ms
5,616 KB
testcase_81 AC 2 ms
5,760 KB
testcase_82 AC 3 ms
5,532 KB
testcase_83 AC 20 ms
11,556 KB
testcase_84 AC 19 ms
11,616 KB
testcase_85 AC 10 ms
8,924 KB
testcase_86 AC 13 ms
11,316 KB
testcase_87 AC 13 ms
11,556 KB
testcase_88 AC 4 ms
5,660 KB
testcase_89 AC 21 ms
11,636 KB
testcase_90 AC 12 ms
8,800 KB
testcase_91 AC 9 ms
8,540 KB
testcase_92 AC 6 ms
6,096 KB
testcase_93 AC 15 ms
11,320 KB
testcase_94 AC 15 ms
9,052 KB
testcase_95 AC 15 ms
9,000 KB
testcase_96 AC 14 ms
11,748 KB
testcase_97 AC 8 ms
8,424 KB
testcase_98 AC 17 ms
11,776 KB
testcase_99 AC 9 ms
8,664 KB
testcase_100 AC 20 ms
11,584 KB
testcase_101 AC 5 ms
5,848 KB
testcase_102 AC 3 ms
5,692 KB
testcase_103 AC 5 ms
5,996 KB
testcase_104 AC 7 ms
8,280 KB
testcase_105 AC 12 ms
11,396 KB
testcase_106 AC 9 ms
8,412 KB
testcase_107 AC 16 ms
11,600 KB
testcase_108 AC 19 ms
11,692 KB
testcase_109 AC 13 ms
11,248 KB
testcase_110 AC 11 ms
9,040 KB
testcase_111 AC 13 ms
11,284 KB
testcase_112 AC 6 ms
8,360 KB
testcase_113 AC 11 ms
9,132 KB
testcase_114 AC 8 ms
8,428 KB
testcase_115 AC 4 ms
5,684 KB
testcase_116 AC 11 ms
8,800 KB
testcase_117 AC 6 ms
8,236 KB
testcase_118 AC 20 ms
11,628 KB
testcase_119 AC 9 ms
8,644 KB
testcase_120 AC 15 ms
11,448 KB
testcase_121 AC 5 ms
6,000 KB
testcase_122 AC 10 ms
8,596 KB
testcase_123 AC 2 ms
5,352 KB
testcase_124 AC 27 ms
17,880 KB
testcase_125 AC 25 ms
18,044 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(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
struct graph{
  int N;
  int*es;
  int**edge;
  void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
      es[B[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];
      edge[B[i]][es[B[i]]++] = A[i];
    }
  }
  inline void bccDFS(int v, int u, int *res, int *rt, int &rts, int *S, int &Ss, int *inS, int *num, int &tm){
    int i;
    int k;
    num[v] = ++tm;
    S[Ss++] = v;
    inS[v] = 1;
    rt[rts++] = v;
    for(i=(0);i<(es[v]);i++){
      int w = edge[v][i];
      if(!num[w]){
        bccDFS(w, v, res, rt, rts, S, Ss, inS, num, tm);
      }
      else if(u != w && inS[w]){
        while(num[rt[rts-1]] > num[w]){
          rts--;
        }
      }
    }
    if(v == rt[rts-1]){
      k = S[Ss-1];
      for(;;){
        int w = S[--Ss];
        inS[w] = 0;
        res[w] = k;
        if(v==w){
          break;
        }
      }
      rts--;
    }
  }
  int bcc(int res[], void *mem=wmem){
    int i;
    int k;
    int*rt;
    int*S;
    int*num;
    int*inS;
    pair<int,int>*arr;
    int rts = 0;
    int Ss = 0;
    int tm = 0;
    walloc1d(&num, N, &mem);
    walloc1d(&rt, N, &mem);
    walloc1d(&S, N, &mem);
    walloc1d(&inS, N, &mem);
    memset(num, 0, sizeof(int)*N);
    memset(inS, 0, sizeof(int)*N);
    for(i=(0);i<(N);i++){
      if(!num[i]){
        bccDFS(i, N, res, rt, rts, S, Ss, inS, num, tm);
      }
    }
    arr = (pair<int,int>*)mem;
    for(i=(0);i<(N);i++){
      arr[i].first = res[i];
      arr[i].second = i;
    }
    sort(arr, arr+N);
    k = 0;
    for(i=(0);i<(N);i++){
      if(i && arr[i].first != arr[i-1].first){
        k++;
      }
      res[arr[i].second] = k;
    }
    return k+1;
  }
}
;
int N;
int A[100000];
int B[100000];
graph g;
int r[100000];
int ress;
int res[100000];
int main(){
  int i;
  wmem = memarr;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
      rd(B[Lj4PdHRW]);B[Lj4PdHRW] += (-1);
    }
  }
  g.setEdge(N,N,A,B);
  g.bcc(r);
  for(i=(0);i<(N);i++){
    if(r[A[i]] == r[B[i]]){
      res[ress++] = i;
    }
  }
  wt_L(ress);
  wt_L('\n');
  {
    int RZTsC2BF;
    if(ress==0){
      wt_L('\n');
    }
    else{
      for(RZTsC2BF=(0);RZTsC2BF<(ress-1);RZTsC2BF++){
        wt_L(res[RZTsC2BF]+1);
        wt_L(' ');
      }
      wt_L(res[RZTsC2BF]+1);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20201003-1

// --- original code ---
// int N, A[1d5], B[1d5];
// graph g;
// int r[1d5];
// int ress, res[1d5];
// {
//   rd(N,(A--,B--)(N));
//   g.setEdge(N,N,A,B);
//   g.bcc(r);
//   rep(i,N) if(r[A[i]] == r[B[i]]) res[ress++] = i;
//   wt(ress);
//   wt(res(ress)+1);
// }
0