洛谷题目p1364
#include<bits/stdc++.h>
using namespace std;
int main()
{
int r[101],f[101][101],minn=99999999;
for(int i=1;i<=100;i++)
for(int j=1;j<=100;j++)
if(i==j)
f[i][j]=0;
else
f[i][j]=minn;
int n,a,b;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>r[i]>>a>>b;
if(a)
f[a][i]=f[i][a]=1;
if(b)
f[b][i]=f[i][b]=1;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
for(int i=1;i<=n;i++)
{
int s=0;
for(int j=1;j<=n;j++)
s+=f[i][j]*r[j];
if(s<minn)
minn=s;
}
cout<<minn;
return 0;
}
p1229
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char a[10002],b[10002];
cin>>a;
cin>>b;
int len=strlen(a),ans=1;
for(int i=0;i<=len-2;i++)
for(int j=0;j<=len-1;j++)
if(b[j]==a[i]&&b[j-1]==a[i+1]) ans*=2;
cout<<ans;
return 0;
}
p3384
#include<bits/stdc++.h>
using namespace std;
struct node{
int father;
int leftchild;
int rightchild;
int deep;
int data;
}a[10001];
int sum[101];
int lca(int x,int y){
a[x].data=1;
while(a[x].father!=0){
x=a[x].father;
a[x].data=1;
}
while(a[y].data!=1){
y=a[y].father;
}
return y;
}
int main(){
int n,x,y,s,t,maxx=1;
cin>>n;
a[1].deep=1;
a[1].father=0;
for(int i=1;i<n;i++){
cin>>x>>y;
if(a[x].leftchild==0)
a[x].leftchild=y;
else
a[x].rightchild=y;
a[y].father=x;
a[y].deep=a[x].deep+1;
if(a[y].deep>maxx)
maxx=a[y].deep;
}
cin>>s>>t;
int f=lca(s,t),num=0,num1=0;
while(s!=f){
s=a[s].father;
num++;
}
num*=2;
while(t!=f){
t=a[t].father;
num1++;
}
for(int i=1;i<=n;i++)
sum[a[i].deep]++;
sort(sum+1,sum+1+100);
cout<<maxx<<endl<<sum[100]<<endl<<num+num1;
return 0;
}