QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#80611 | #5173. 染色 | huzhaoyang | 0 | 934ms | 113640kb | C++14 | 1.8kb | 2023-02-24 14:28:42 | 2023-02-24 14:28:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
int n,m,q,x,y,z,v[N];
struct Tree{
int rt,dfn[N],dep[N],fa[N][20],f[N];
ll d[N];vector<int>e[N];
int lca(int x,int y){
if (dep[x]<dep[y])swap(x,y);
for(int i=19;i>=0;i--)
if (dep[fa[x][i]]>=dep[y])x=fa[x][i];
if (x==y)return x;
for(int i=19;i>=0;i--)
if (fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
return fa[x][0];
}
void dfs(int k,int f,int s){
dfn[k]=++dfn[0],dep[k]=s,fa[k][0]=f;
for(int i=1;i<20;i++)fa[k][i]=fa[fa[k][i-1]][i-1];
for(int i:e[k])dfs(i,k,s+1);
}
int find(int k){
if (k==f[k])return k;
int F=find(f[k]);d[k]+=d[f[k]];return f[k]=F;
}
void merge(int x,int y,int z){
int x0=find(x),y0=find(y);
if (x0!=y0)f[y0]=x0,d[y0]=d[x]-d[y]+z;
}
void read(){
for(int i=1;i<=n;i++){
scanf("%d",&x);
if (x<0)rt=i;
else e[x].push_back(i);
}
dfs(rt,0,0);
for(int i=1;i<=n;i++)f[i]=i,d[i]=0;
}
}T1,T2;
bool cmp(int x,int y){
return T2.dfn[x]<T2.dfn[y];
}
int main(){
scanf("%d%d%*d%d",&n,&m,&q);
T1.read(),T2.read();
for(int i=1;i<=n;i++)v[T1.dfn[i]]=i;
sort(v+1,v+m+1,cmp);
for(int i=1;i<=m;i++)printf("%d ",v[i]);
puts(""),fflush(stdout);
for(int i=1;i<m;i++)printf("? %d %d\n",v[i],v[i+1]);
puts("!"),fflush(stdout);
for(int i=1;i<m;i++){
scanf("%d%d",&x,&y);
z=T1.lca(v[i],v[i+1]);
T1.merge(z,v[i],x),T1.merge(z,v[i+1],y);
scanf("%d%d",&x,&y);
z=T2.lca(v[i],v[i+1]);
T2.merge(z,v[i],x),T2.merge(z,v[i+1],y);
}
for(int i=1;i<=n;i++)T1.find(i),T2.find(i);
for(int i=1;i<=q;i++){
scanf("%d%d",&x,&y);
z=T1.lca(x,y);
printf("%lld ",T1.d[x]+T1.d[y]-(T1.d[z]<<1));
z=T2.lca(x,y);
printf("%lld\n",T2.d[x]+T2.d[y]-(T2.d[z]<<1));
}
fflush(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 71576kb
input:
10000 100 84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0 0 ? 0...
result:
wrong answer 1st words differ - expected: '3668', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 68ms
memory: 71256kb
input:
100000 100000 3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st words differ - expected: '113194', found: '0'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 12ms
memory: 71540kb
input:
5000 5000 256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st words differ - expected: '1322', found: '0'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 934ms
memory: 113640kb
input:
1000000 1000000 1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st words differ - expected: '1263815', found: '0'