Compare commits
2 Commits
a1480a359a
...
cdc9464526
Author | SHA1 | Date | |
---|---|---|---|
cdc9464526 | |||
5de2ef354f |
31
src/B3637/B3637.cpp
Normal file
31
src/B3637/B3637.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
|
||||
using ll = int;
|
||||
|
||||
// const ll max_n = (ll)1e6+5;
|
||||
// ll a[max_n], f[max_n];
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
|
||||
ll n;
|
||||
std::cin>>n;
|
||||
const ll max_n = (ll)5e3+5;
|
||||
ll *a = new ll[max_n], *f = new ll[max_n];
|
||||
for(ll i{1};i<=n;i++){
|
||||
std::cin>>a[i];
|
||||
}
|
||||
std::fill(f, f+max_n, 1);
|
||||
ll max{};
|
||||
for(ll i{2};i<=n;i++){
|
||||
for(ll j{1};j<i;j++){
|
||||
if(a[i]>a[j]){
|
||||
f[i] = std::max(f[i], f[j]+1);
|
||||
}
|
||||
}
|
||||
max = std::max(max, f[i]);
|
||||
}
|
||||
std::cout<<max<<'\n';
|
||||
}
|
63
src/B4016/B4016.cpp
Normal file
63
src/B4016/B4016.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using ll = int64_t;
|
||||
|
||||
int main(){
|
||||
std::iostream::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
|
||||
|
||||
const ll max_n = 1e5+5;
|
||||
ll n;
|
||||
std::cin>>n;
|
||||
auto *edge = new std::vector<ll>[max_n];
|
||||
ll a, b;
|
||||
for(ll i{1}; i<n; i++){
|
||||
std::cin>>a>>b;
|
||||
edge[a].push_back(b);
|
||||
edge[b].push_back(a);
|
||||
}
|
||||
std::queue<std::pair<ll, ll>> q;
|
||||
q.emplace(0, a);
|
||||
std::bitset<max_n> vis;
|
||||
vis[a]=true;
|
||||
ll max_a{}, max{};
|
||||
while(!q.empty()){
|
||||
auto top = q.front();
|
||||
q.pop();
|
||||
if(top.first > max){
|
||||
max = top.first;
|
||||
max_a = top.second;
|
||||
}
|
||||
for(auto &i:edge[top.second]){
|
||||
if(vis[i]){
|
||||
continue;
|
||||
}
|
||||
q.push({top.first + 1, i});
|
||||
vis[i] = true;
|
||||
}
|
||||
}
|
||||
q = std::queue<std::pair<ll, ll>>();
|
||||
q.emplace(0, max_a);
|
||||
vis.reset();
|
||||
vis[max_a]=true;
|
||||
ll ans{};
|
||||
while(!q.empty()){
|
||||
auto top = q.front();
|
||||
q.pop();
|
||||
ans = std::max(ans, top.first);
|
||||
for(auto i: edge[top.second]){
|
||||
if(vis[i]){
|
||||
continue;
|
||||
}
|
||||
q.push({top.first+1, i});
|
||||
vis[i] = true;
|
||||
}
|
||||
}
|
||||
std::cout<<ans<<'\n';
|
||||
}
|
Loading…
Reference in New Issue
Block a user