QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#629 | #413473 | #8671. 分流器 | Milmon | ANIG | Success! | 2024-05-22 20:17:22 | 2024-05-22 20:17:24 |
Details
Extra Test:
Wrong Answer
time: 220ms
memory: 4504kb
input:
50000 2 20001 3 20001 4 20001 5 20001 6 20001 7 20001 8 20001 9 20001 10 20001 11 20001 12 20001 13 20001 14 20001 15 20001 16 20001 17 20001 18 20001 19 20001 20 20001 21 20001 22 20001 23 20001 24 20001 25 20001 26 20001 27 20001 28 20001 29 20001 30 20001 31 20001 32 20001 33 20001 34 20001 35 20...
output:
398027684033796659235430720619120245370477278049242593871342686565238635974930057042676009749975595510836461137504912702831400376935319143621753470415827025981215282426893498224826615977707595539466961019588699726772279731941315198182787264034852821200164566127930390710398182979935327718016873784821...
result:
wrong answer 1st lines differ - expected: '794090351913296032413251784349...1581095988135833790694215909376', found: '398027684033796659235430720619...9869570675234892321663406309376'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#413473 | #8671. 分流器 | ANIG | 97 | 11ms | 4716kb | C++23 | 1.6kb | 2024-05-17 16:43:30 | 2024-05-26 03:01:33 |
answer
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned short
const int N=5e4+5;
int n,to[N][2],dp[N],rd[N];
ull f[N];
ull pows(int a,int b){
if(b==0)return 1;
ull res=pows(a,b>>1);
res=res*res;
if(b&1)res=res*a;
return res;
}
deque<int>q;
int lcm(int a,int b){
if(!a||!b)return a|b;
return a*b/__gcd(a,b);
}
signed main(){
cin.tie(nullptr),cout.tie(nullptr)->sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)cin>>to[i][0]>>to[i][1],rd[to[i][0]]++,rd[to[i][1]]++;
for(int i=1;i<=n;i++){
int op;
cin>>op;
if(op)swap(to[i][0],to[i][1]);
}
q.push_back(1);
dp[1]=1;f[1]=1;
while(q.size()){
int x=q.front();
q.pop_front();
if(f[x]&1)dp[x]++,f[x]<<=1;
int c=to[x][0],k=max(dp[x],dp[c]);
// cout<<x<<" "<<dp[x]<<" "<<f[x]<<endl;
if(dp[c]){
f[c]=f[c]*pows(2,k-dp[c])+(f[x]>>1)*pows(2,k-dp[x]);
}else{
f[c]=(f[x]>>1)*pows(2,k-dp[x]);
}
dp[c]=k;
rd[c]--;
if(!rd[c])q.push_back(c);
c=to[x][1],k=max(dp[x],dp[c]);
if(dp[c]){
f[c]=f[c]*pows(2,k-dp[c])+(f[x]>>1)*pows(2,k-dp[x]);
}else{
f[c]=(f[x]>>1)*pows(2,k-dp[x]);
}
dp[c]=k;
rd[c]--;
if(!rd[c])q.push_back(c);
}
vector<int> ans={1};
int cnt=dp[n+1]-1;
while(cnt--){
for(int i=0; i<ans.size(); i++){
ans[i]=ans[i]*2;
}
for(int i=0; i<ans.size(); i++){
if(i==ans.size()-(int)(1)){
if(ans[i]/10){
ans.emplace_back(0);
}
}
ans[i+1]+=ans[i]/10;
ans[i]%=10;
}
}
reverse(ans.begin(),ans.end());
for(auto p:ans) cout<<p;
cout<<'\n';
}