当前位置:网站首页>Ccf-csp 202112-5 extreme path violence 12 points
Ccf-csp 202112-5 extreme path violence 12 points
2022-06-09 02:43:00 【Confident little screw】
Original link :CCF-CSP 202112-5 Range path 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e5+10;
int n,k1,k2;
vector<int> g[N];
vector<int> v;
int vis[N];
set<pair<int,int>> res;
void dfs(int x,vector<int>& v,int y)
{
int minnum=min(x,y)-k1;
int maxnum=max(x,y)+k2;
int minp=*(min_element(v.begin(),v.end()));
int maxp=*(max_element(v.begin(),v.end()));
if(minnum<=minp && minp<=maxp && maxp<=maxnum)
{
int a=x,b=y;
if(a>b) swap(a,b);
pair<int,int> p=make_pair(a,b);
res.insert(p);
}
for(int i=0;i<g[y].size();i++)
{
int tmp=g[y][i];
if(vis[tmp]==0)
{
v.push_back(tmp);
vis[tmp]=1;
dfs(x,v,tmp);
v.pop_back();
vis[tmp]=0;
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>k1>>k2;
if(n<=5000)
{
for(int i=0;i<n-1;i++)
{
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
v.clear();
v.push_back(i);
vis[i]=1;
dfs(i,v,i);
}
cout<<res.size()<<endl;
}
return 0;
}
边栏推荐
- Ccf-csp 201903-4 messaging interface
- Typescript base type - type assertion
- GeoTrust certificate price
- Ccp-csp 201909-3 character drawing 100
- Ccf-csp 201409-3 string matching
- Backup and restore methods of MySQL database
- How does Jerry's SPI slave configure the driver? [chapter]
- Modbus RTU communication routine between Delta Eh3 series PLC and thermostat
- The latest investment report of animoca brands: 340+ investment projects, with a total investment of US $1.5 billion and a total reserve capital of more than 5billion
- Ccf-csp 201803-5 quadratic summation 30 points
猜你喜欢

Leetcode 1371. Each vowel contains an even number of times the longest substring XOR + prefix and

In unity, inherit the lifecycle of monobehavior game objects

Leetcode 974. And K divisible subarray prefix sum

飞书要不要做生态?剖析第一家 All in 飞书的独立 SaaS 案例

Fight the high vision medical service of HKEx again, the gospel of short-sighted partners?

LocalTime 、LocalDate 、LocalDateTime

Ccf-csp 201803-5 quadratic summation 30 points

Ccf-csp 201803-3 URL mapping 100 points

【编码推流】SRS流媒体服务器安装及使用

Basic architecture of data Lake
随机推荐
Basic method for missing data filling (2) -- random forest (missforest) filling
vins estimator ProcessImage
Rcgi column - region of Overseas Social Market Research (including lottery)
Basic principle of digital circuit adder (I)
进程与线程
杰理之AD 值的硬件计算原理?【篇】
Leetcode 238. Product of arrays other than itself
Export related knowledge
Modbus RTU communication routine between Delta Eh3 series PLC and thermostat
【网络协议】| 【01】网络字节序大端、小端
Ccf-csp 201812-4 data center minimum spanning tree
测试、预发布、生产环境测试时的侧重点是哪些?
Formatting and parsing of simpledateformat time
[MySQL from Xiaobai to expert] Part 6: transaction and JDBC programming in MySQL
Acwing 791 high precision addition
[coding streaming] installation and use of SRS streaming media server
Sectigo certificate price
Jerry's SPI host [chapter]
Docker安装Redis
C#中的反射原理及应用