結果
問題 | No.1153 ねこちゃんゲーム |
ユーザー | LayCurse |
提出日時 | 2020-08-07 22:30:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 7,374 bytes |
コンパイル時間 | 3,202 ms |
コンパイル使用メモリ | 227,656 KB |
実行使用メモリ | 71,724 KB |
最終ジャッジ日時 | 2024-09-24 21:04:08 |
合計ジャッジ時間 | 21,932 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
27,196 KB |
testcase_01 | AC | 7 ms
20,188 KB |
testcase_02 | AC | 7 ms
20,140 KB |
testcase_03 | AC | 9 ms
21,800 KB |
testcase_04 | AC | 8 ms
21,820 KB |
testcase_05 | AC | 8 ms
23,052 KB |
testcase_06 | AC | 8 ms
20,452 KB |
testcase_07 | AC | 205 ms
48,408 KB |
testcase_08 | AC | 211 ms
48,760 KB |
testcase_09 | AC | 207 ms
48,252 KB |
testcase_10 | AC | 210 ms
47,980 KB |
testcase_11 | AC | 200 ms
48,336 KB |
testcase_12 | AC | 218 ms
48,564 KB |
testcase_13 | AC | 212 ms
47,940 KB |
testcase_14 | AC | 200 ms
48,204 KB |
testcase_15 | AC | 202 ms
48,628 KB |
testcase_16 | AC | 208 ms
47,788 KB |
testcase_17 | AC | 210 ms
48,532 KB |
testcase_18 | AC | 224 ms
50,040 KB |
testcase_19 | AC | 219 ms
49,960 KB |
testcase_20 | AC | 223 ms
51,580 KB |
testcase_21 | AC | 232 ms
51,444 KB |
testcase_22 | AC | 217 ms
51,320 KB |
testcase_23 | AC | 214 ms
49,160 KB |
testcase_24 | AC | 223 ms
49,784 KB |
testcase_25 | AC | 227 ms
50,572 KB |
testcase_26 | AC | 228 ms
49,984 KB |
testcase_27 | AC | 202 ms
63,812 KB |
testcase_28 | AC | 302 ms
71,724 KB |
testcase_29 | AC | 270 ms
70,648 KB |
testcase_30 | AC | 277 ms
69,556 KB |
testcase_31 | AC | 190 ms
55,160 KB |
testcase_32 | AC | 112 ms
41,472 KB |
testcase_33 | AC | 112 ms
45,944 KB |
testcase_34 | AC | 117 ms
46,068 KB |
testcase_35 | AC | 104 ms
45,944 KB |
testcase_36 | AC | 117 ms
43,492 KB |
testcase_37 | TLE | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
ソースコード
#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(k)){ continue; } chked.insert(k); 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(k)) continue; // chked.insert(k); // 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"); // }