Master of Data Structure 虚树

链接
m<2000
建虚树后暴力
维护虚树中两点间的实际点的个数 模拟即可
巨丑的代码

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define yes puts("YES")
#define no puts("NO")
#define err puts("-1")
#define ios ios::sync_with_stdio(0);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int maxn = 5e5 + 6;
const LL inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
LL qp(LL x,LL y)
{
   
    LL ans=1;
    x%=mod;
    while(y)
    {
   
        if(y&1)
            ans=ans*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ans;
}
LL inv(LL x)
{
   
    return qp(x,mod-2);
}

//head
int lgN,n,m,op[maxn],dfn[maxn],b[maxn],u[maxn],v[maxn],k[maxn],dep[maxn],tot;
int fa[maxn][30];
VI G[maxn],fake[maxn];
void dfs(int u,int f)
{
   
    dep[u]=dep[f]+1;
    fa[u][0]=f;
    dfn[u]=++tot;
    for(int i=1; i<=lgN; i++)
    {
   
        fa[u][i]=fa[fa[u][i-1]][i-1];
    }
    for(int v:G[u])
        if(v!=f)
        {
   
            dfs(v,u);
        }
}
int anc[maxn],dp[maxn];
void dfs1(int u,int f)
{
   
    anc[u]=f;
    dp[u]=dp[f]+1;
    for(int v:fake[u])
    {
   
        dfs1(v,u);
    }
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
clear all; % TODO: Edit this to point to the folder your caffe mex file is in. % path_to_matcaffe = '/data/jkrause/cs231b/caffe-rc2/matlab/caffe'; path_to_matcaffe = 'C:/Users/DELL/Downloads/caffe-master/windows'; addpath(path_to_matcaffe) % Load up the image im = imread('peppers.png'); % Get some random image regions (format of each row is [x1 y1 x2 y2]) % Note: If you want to change the number of regions you extract features from, % then you need to change the first input_dim in cnn_deploy.prototxt. regions = [ 1 1 100 100; 100 50 400 250; 1 1 512 284; 200 200 230 220 100 100 300 200]; % Convert image from RGB to BGR and single, which caffe requires. im = single(im(:,:,[3 2 1])); % Get the image mean and crop it to the center mean_data = load('ilsvrc_2012_mean.mat'); image_mean = mean_data.image_mean; cnn_input_size = 227; % Input size to the cnn we trained. off = floor((size(image_mean,1) - cnn_input_size)/2)+1; image_mean = image_mean(off:off+cnn_input_size-1, off:off+cnn_input_size-1, :); % Extract each region ims = zeros(cnn_input_size, cnn_input_size, 3, size(regions, 1), 'single'); for i = 1:size(regions, 1) r = regions(i,:); reg = im(r(2):r(4), r(1):r(3), :); % Resize to input CNN size and subtract mean reg = imresize(reg, [cnn_input_size, cnn_input_size], 'bilinear', 'antialiasing', false); reg = reg - image_mean; % Swap dims 1 and 2 to work with caffe ims(:,:,:,i) = permute(reg, [2 1 3]); end % Initialize caffe with our network. % -cnn_deploy.prototxt gives the structure of the network we're using for % extracting features and is how we specify we want fc6 features. % -cnn512.caffemodel is the binary network containing all the learned weights. % -'test' indicates that we're only going to be extracting features and not % training anything init_key = caffe('init', 'cnn_deploy.prototxt', 'cnn512.caffemodel', 'test'); caffe('set_device', 0); % Specify which gpu we want to use. In this case, let's use the first gpu. caffe('set_mode_gpu'); %caffe('set_mode_cpu'); % Use if you want to use a cpu for whatever reason % Run the CNN f = caffe('forward', {ims}); % Convert the features to (num. dims) x (num. regions) feat = single(reshape(f{1}(:), [], size(ims, 4)));
最新发布
05-22
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值