結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | LayCurse |
提出日時 | 2020-08-07 22:31:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 258 ms / 2,500 ms |
コード長 | 7,374 bytes |
コンパイル時間 | 3,874 ms |
コンパイル使用メモリ | 227,300 KB |
実行使用メモリ | 72,440 KB |
最終ジャッジ日時 | 2024-09-24 21:05:24 |
合計ジャッジ時間 | 18,751 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
20,980 KB |
testcase_01 | AC | 8 ms
21,484 KB |
testcase_02 | AC | 8 ms
21,568 KB |
testcase_03 | AC | 8 ms
20,196 KB |
testcase_04 | AC | 8 ms
22,916 KB |
testcase_05 | AC | 8 ms
20,316 KB |
testcase_06 | AC | 7 ms
20,136 KB |
testcase_07 | AC | 191 ms
48,632 KB |
testcase_08 | AC | 198 ms
48,740 KB |
testcase_09 | AC | 187 ms
50,680 KB |
testcase_10 | AC | 186 ms
48,564 KB |
testcase_11 | AC | 179 ms
47,584 KB |
testcase_12 | AC | 180 ms
48,764 KB |
testcase_13 | AC | 196 ms
48,632 KB |
testcase_14 | AC | 200 ms
48,500 KB |
testcase_15 | AC | 214 ms
48,116 KB |
testcase_16 | AC | 188 ms
48,132 KB |
testcase_17 | AC | 183 ms
48,608 KB |
testcase_18 | AC | 210 ms
52,088 KB |
testcase_19 | AC | 206 ms
50,044 KB |
testcase_20 | AC | 216 ms
50,912 KB |
testcase_21 | AC | 200 ms
50,956 KB |
testcase_22 | AC | 186 ms
48,928 KB |
testcase_23 | AC | 199 ms
48,924 KB |
testcase_24 | AC | 199 ms
49,320 KB |
testcase_25 | AC | 199 ms
50,664 KB |
testcase_26 | AC | 196 ms
50,288 KB |
testcase_27 | AC | 185 ms
64,312 KB |
testcase_28 | AC | 247 ms
72,440 KB |
testcase_29 | AC | 258 ms
70,652 KB |
testcase_30 | AC | 255 ms
69,852 KB |
testcase_31 | AC | 191 ms
55,044 KB |
testcase_32 | AC | 105 ms
43,364 KB |
testcase_33 | AC | 105 ms
43,284 KB |
testcase_34 | AC | 107 ms
41,628 KB |
testcase_35 | AC | 104 ms
45,944 KB |
testcase_36 | AC | 109 ms
43,908 KB |
testcase_37 | AC | 52 ms
42,916 KB |
testcase_38 | AC | 46 ms
41,556 KB |
testcase_39 | AC | 48 ms
41,252 KB |
testcase_40 | AC | 52 ms
45,684 KB |
testcase_41 | AC | 46 ms
41,460 KB |
ソースコード
#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'); } } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } struct graph{ int N; int *es; int **edge; void setEdgeRootedTree(int N__, int M, int A[], int B[], int root=0, int reorder=0, int cnv[] = NULL, void **mem = &wmem){ int i; int j; int k; int *dist; int *q; int qs; int qe; int *ind; void *tmem; N = N__; tmem = ((char*)(*mem)) + (sizeof(int) * N + 15) + (sizeof(int*) * N + 15) + (sizeof(int) * M + 15 * 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], &tmem); } 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]; } walloc1d(&dist, N, &tmem); walloc1d(&q, N, &tmem); walloc1d(&ind, N, &tmem); if(cnv==NULL){ walloc1d(&cnv, N, &tmem); } for(i=(0);i<(N);i++){ dist[i] = -1; } dist[root] = 0; qs = qe = 0; q[qe++] = root; while(qs < qe){ i = q[qs++]; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; if(dist[k]==-1){ dist[k] = dist[i] + 1; q[qe++] = k; } } } if(reorder == 0){ for(i=(0);i<(N);i++){ cnv[i] = i; } for(i=(0);i<(N);i++){ ind[i] = i; } } else{ for(i=(0);i<(N);i++){ cnv[i] = q[i]; } for(i=(0);i<(N);i++){ ind[cnv[i]] = i; } } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ j = A[i]; k = B[i]; if(dist[j] > dist[k]){ swap(j, k); } es[ind[j]]++; } 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++){ j = A[i]; k = B[i]; if(dist[j] > dist[k]){ swap(j, k); } j = ind[j]; k = ind[k]; edge[j][es[j]++] = k; } } } ; int N; int M; int A[200000]; int U[200000]; int V[200000]; graph g; int up[200000]; int dw_g[200000]; int tot_g[200000]; int up_g[200000]; map<int,int> s[200000]; void dfs(int n){ int Lj4PdHRW; int i; for(Lj4PdHRW=(0);Lj4PdHRW<(g.es[n]);Lj4PdHRW++){ auto &i = g.edge[n][Lj4PdHRW]; up[i] = n; dfs(i); s[n][dw_g[i]]++; } for(i=0;;i++){ if(s[n].count(i)==0 || s[n][i]==0){ break; } } dw_g[n] = i; } void dfs2(int n){ int t_ynMSdg; int i; int j; int k; if(up[n] != -1){ k = up[n]; s[k][dw_g[n]]--; for(i=0;;i++){ if(s[k].count(i)==0 || s[k][i]==0){ break; } } up_g[n] = i; s[k][dw_g[n]]++; s[n][up_g[n]]++; } for(i=0;;i++){ if(s[n].count(i)==0 || s[n][i]==0){ break; } } tot_g[n] = i; for(t_ynMSdg=(0);t_ynMSdg<(g.es[n]);t_ynMSdg++){ auto &i = g.edge[n][t_ynMSdg]; dfs2(i); } } int main(){ wmem = memarr; int i; int j; int k; int x = 0; set<int> chked; rd(N); rd(M); { int tU__gIr_; for(tU__gIr_=(0);tU__gIr_<(M);tU__gIr_++){ rd(A[tU__gIr_]);A[tU__gIr_] += (-1); } } { int V9aVTaxx; for(V9aVTaxx=(0);V9aVTaxx<(N-1);V9aVTaxx++){ rd(U[V9aVTaxx]);U[V9aVTaxx] += (-1); rd(V[V9aVTaxx]);V[V9aVTaxx] += (-1); } } g.setEdgeRootedTree(N,N-1,U,V); up[0] = -1; dfs(0); dfs2(0); for(i=(0);i<(M);i++){ x ^= tot_g[A[i]]; } if(x==0){ wt_L(-1); wt_L(' '); wt_L(-1); wt_L('\n'); return 0; } for(k=(0);k<(M);k++){ int AlM5nNnR; i = A[k]; if(chked.count(i)){ continue; } chked.insert(i); if(up[i] >= 0 && (x ^ tot_g[i] ^ up_g[i])==0){ wt_L(k+1); wt_L(' '); wt_L(up[i]+1); wt_L('\n'); return 0; } for(AlM5nNnR=(0);AlM5nNnR<(g.es[i]);AlM5nNnR++){ auto &j = g.edge[i][AlM5nNnR]; if((x ^ tot_g[i] ^ dw_g[j])==0){ wt_L(k+1); wt_L(' '); wt_L(j+1); wt_L('\n'); return 0; } } } wt_L("not found"); wt_L('\n'); return 0; } // cLay varsion 20200509-1 // --- original code --- // int N, M, A[2d5], U[2d5], V[2d5]; // // graph g; // int up[2d5], dw_g[2d5], tot_g[2d5], up_g[2d5]; // map<int,int> s[2d5]; // // void dfs(int n){ // int i; // rep[g.edge[n]](i,g.es[n]){ // up[i] = n; // dfs(i); // s[n][dw_g[i]]++; // } // for(i=0;;i++) if(s[n].count(i)==0 || s[n][i]==0) break; // dw_g[n] = i; // } // // void dfs2(int n){ // int i, j, k; // // if(up[n] != -1){ // k = up[n]; // s[k][dw_g[n]]--; // for(i=0;;i++) if(s[k].count(i)==0 || s[k][i]==0) break; // up_g[n] = i; // s[k][dw_g[n]]++; // s[n][up_g[n]]++; // } // for(i=0;;i++) if(s[n].count(i)==0 || s[n][i]==0) break; // tot_g[n] = i; // // rep[g.edge[n]](i,g.es[n]){ // dfs2(i); // } // } // // { // int i, j, k, x = 0; // set<int> chked; // // rd(N,M,(A--)(M),(U--,V--)(N-1)); // g.setEdgeRootedTree(N,N-1,U,V); // // up[0] = -1; // dfs(0); // dfs2(0); // // // rep(i,N) wt(i,dw_g[i],up_g[i],tot_g[i]); // // rep(i,M) x ^= tot_g[A[i]]; // if(x==0) wt(-1, -1), return 0; // // rep(k,M){ // i = A[k]; // if(chked.count(i)) continue; // chked.insert(i); // if(up[i] >= 0 && (x ^ tot_g[i] ^ up_g[i])==0) wt(k+1, up[i]+1), return 0; // rep[g.edge[i]](j,g.es[i]){ // if((x ^ tot_g[i] ^ dw_g[j])==0) wt(k+1, j+1), return 0; // } // } // // wt("not found"); // }