#Div2.

##A

##B

#Div1.

##A Xor-tree

###Task

###Solution

###Code

最长耗时93 MS


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=100005;
vector <int> e[maxn];
vector <int> s[maxn];
typedef vector<int>::iterator ii;
int n;
int vis[maxn],q[maxn],ql,qr;
int init[maxn],goal[maxn];
int sel[maxn],fasel[maxn],fafasel[maxn];
void dfs(int u)
{
if ((fafasel[u]^init[u])!=goal[u])
sel[u]=true;
for (ii v=s[u].begin();v!=s[u].end();v++)
{
fasel[*v]^=(sel[u]^fafasel[u]);
fafasel[*v]^=fasel[u];
dfs(*v);
}
}
int main()
{
int u,v;
scanf("%d",&n);
for (int i=1;i<n;i++)
scanf("%d%d",&u,&v),e[u].push_back(v),e[v].push_back(u);
for (int i=1;i<=n;i++)
scanf("%d",&init[i]);
for (int i=1;i<=n;i++)
scanf("%d",&goal[i]);
q[ql=qr=1]=1;
for (;ql<=qr;ql++)
{
vis[u=q[ql]]=1;
for (ii v=e[u].begin();v!=e[u].end();v++)
if (!vis[*v])
s[u].push_back(q[++qr]=*v);
}
dfs(1);
int cnt=0;
for (int i=1;i<=n;i++)
cnt+=sel[i];
printf("%d\n",cnt);
for (int i=1;i<=n;i++)
{
if (sel[i])
printf("%d\n",i);
}
return 0;
}


##B Working out

###Task

Summer is coming! It’s time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix $a$ with $n$ lines and $m$ columns. Let number $a[i][j]$ represents the calories burned by performing workout at the cell of gym in the $i$-th line and the $j$-th column.

Iahub starts with workout located at line $1$ and column $1$. He needs to finish with workout $a[n][m]$. After finishing workout $a[i][j]$, he can go to workout $a[i + 1][j]$ or $a[i][j + 1]$. Similarly, Iahubina starts with workout $a[n]$ and she needs to finish with workout $a[m]$. After finishing workout from cell $a[i][j]$, she goes to either $a[i][j + 1]$ or $a[i - 1][j]$.

There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.

If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.

###Solution

###Code

最长耗时249 MS


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1005;
long long Map[maxn][maxn],f[maxn][maxn],g[maxn][maxn],F[maxn][maxn],G[maxn][maxn];
int m,n;
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
scanf("%lld",&Map[i][j]);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
f[i][j]=max(f[i-1][j],f[i][j-1])+Map[i][j];
for (int i=n;i>=1;i--)
for (int j=1;j<=m;j++)
g[i][j]=max(g[i+1][j],g[i][j-1])+Map[i][j];
for (int i=n;i>=1;i--)
for (int j=m;j>=1;j--)
F[i][j]=max(F[i+1][j],F[i][j+1])+Map[i][j];
for (int i=1;i<=n;i++)
for (int j=m;j>=1;j--)
G[i][j]=max(G[i-1][j],G[i][j+1])+Map[i][j];
long long ans=0,tin,tout;
for (int i=2;i<n;i++)
for (int j=2;j<m;j++)
{
ans=max(ans,
max(f[i-1][j]+g[i][j-1]+F[i+1][j]+G[i][j+1],
f[i][j-1]+g[i+1][j]+F[i][j+1]+G[i-1][j]));
}
printf("%lld\n",ans);
}


##C

##D

##E