update
This commit is contained in:
parent
12ab34e7a4
commit
1dc9892842
41
src/P1137/P1137.cpp
Normal file
41
src/P1137/P1137.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
using ll = long long;
|
||||
|
||||
const ll max_n = 100000+5;
|
||||
ll n, m, ans[max_n], in_degree[max_n];
|
||||
std::vector<ll> next[max_n];
|
||||
std::queue<ll> q;
|
||||
|
||||
int main(){
|
||||
std::cin>>n>>m;
|
||||
for(ll i{1};i<=n;i++)ans[i]=1;
|
||||
for(ll i{1};i<=m;i++){
|
||||
ll a,b;
|
||||
std::cin>>a>>b;
|
||||
next[a].push_back(b);
|
||||
in_degree[b]++;
|
||||
}
|
||||
for(ll i{1};i<=n;i++){
|
||||
if(in_degree[i]==0){
|
||||
q.push(i);
|
||||
}
|
||||
}
|
||||
while(!q.empty()){
|
||||
const ll front = q.front();
|
||||
q.pop();
|
||||
for(const ll i:next[front]){
|
||||
ans[i] = std::max(ans[i],ans[front]+1);
|
||||
--in_degree[i];
|
||||
if(in_degree[i]==0){
|
||||
q.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(ll i{1};i<=n;i++){
|
||||
std::cout<<ans[i]<<'\n';
|
||||
}
|
||||
}
|
158
src/P8817/P8817.cpp
Normal file
158
src/P8817/P8817.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
using ll = long long;
|
||||
|
||||
ll n,m,k,ans;
|
||||
const ll max_n = 10000;
|
||||
std::vector<ll> next[max_n];
|
||||
ll score[max_n];
|
||||
// #define ONLINE_JUDGE
|
||||
#ifdef ONLINE_JUDGE
|
||||
#define DEBUG(code)
|
||||
#else
|
||||
#define DEBUG(code)code
|
||||
#endif
|
||||
|
||||
|
||||
template<class T>
|
||||
std::ostream &operator<<(std::ostream &os,const std::vector<T> &t){
|
||||
os<<"vector { ";
|
||||
if(t.size()>0){
|
||||
for(ll i{0};i<t.size()-1;i++){
|
||||
os<<t[i]<<", ";
|
||||
}
|
||||
os<<*t.rbegin();
|
||||
}
|
||||
os<<" }";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::ostream &operator<<(std::ostream &os,const std::set<T> &t){
|
||||
os<<"set { ";
|
||||
auto it = t.begin();
|
||||
if(t.size()>0){
|
||||
while(*it!=*t.rbegin()){
|
||||
os<<*it++<<", ";
|
||||
}
|
||||
os<<*t.rbegin();
|
||||
}
|
||||
os<<" }";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
std::ostream &operator<<(std::ostream &os,const std::deque<T> &t){
|
||||
os<<"deque { ";
|
||||
for(ll i{0};i<(ll)t.size()-1;i++){
|
||||
os<<t[i]<<", ";
|
||||
}
|
||||
if (t.size()!=0) {
|
||||
os<<*t.rbegin();
|
||||
}
|
||||
os<<" }";
|
||||
return os;
|
||||
}
|
||||
|
||||
struct State{
|
||||
ll now,step,used_k,score;
|
||||
std::set<ll>vis;
|
||||
DEBUG(
|
||||
std::vector<ll> his;
|
||||
)
|
||||
bool operator<(const State &that)const{
|
||||
return this->score>that.score;
|
||||
}
|
||||
friend std::ostream&operator<<(std::ostream &os, State const &s){
|
||||
os<<"State { now: "<<s.now<<", step: "<<s.step<<", used_k: "<<s.used_k<<", score:"<<s.score<<", vis: "<<s.vis DEBUG(<<", his:"<<s.his)<<" }";
|
||||
return os;
|
||||
}
|
||||
};
|
||||
std::priority_queue<State> q;
|
||||
DEBUG(
|
||||
State last_state;
|
||||
)
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
std::cin>>n>>m>>k;
|
||||
for(ll i{2};i<=n;i++){
|
||||
std::cin>>score[i];
|
||||
}
|
||||
for(ll i{1};i<=m;i++){
|
||||
ll u,v;
|
||||
std::cin>>u>>v;
|
||||
next[u].push_back(v);
|
||||
next[v].push_back(u);
|
||||
}
|
||||
DEBUG(
|
||||
std::cout<<next[4]<<'\n';
|
||||
)
|
||||
for(const auto i:next[1]){
|
||||
std::vector<ll> new_his {1,i};
|
||||
std::set<ll> s;
|
||||
s.insert(i);
|
||||
// q.push({i,1,0,score[i],DEBUG(new_his),});
|
||||
q.push({.now=i, .step=1, .used_k=0, .score=score[i], .vis=s, DEBUG(.his=new_his)});
|
||||
new_his[1] = -new_his[1];
|
||||
q.push({.now=i, .step=0, .used_k=1, .score=0, DEBUG(.his=new_his)});
|
||||
}
|
||||
while(!q.empty()){
|
||||
const auto front = q.top();
|
||||
q.pop();
|
||||
DEBUG(std::cout<<front<<'\n';)
|
||||
DEBUG(
|
||||
if(front.now==5){
|
||||
std::cout<<front<<'\n';
|
||||
}
|
||||
)
|
||||
if(front.step==4){
|
||||
if(front.now==1){
|
||||
if(ans<front.score){
|
||||
ans = front.score;
|
||||
DEBUG(
|
||||
last_state = front;
|
||||
)
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for(const auto i:next[front.now]){
|
||||
if(front.vis.find(i)!=front.vis.end()){
|
||||
continue;
|
||||
}
|
||||
auto new_vis = front.vis;
|
||||
new_vis.insert(i);
|
||||
DEBUG(
|
||||
auto old_his = front.his;
|
||||
old_his.push_back(i);
|
||||
)
|
||||
q.push({.now=i, .step=front.step+1, .used_k=0, .score=front.score+score[i], .vis=new_vis, DEBUG(.his=old_his)});
|
||||
}
|
||||
if(front.used_k>=k){
|
||||
continue;
|
||||
}
|
||||
for(const auto i:next[front.now]){
|
||||
DEBUG(
|
||||
auto old_his = front.his;
|
||||
old_his.push_back(-i);
|
||||
)
|
||||
DEBUG(
|
||||
if(front.now==3){
|
||||
std::cout<<next[3]<<'\n';
|
||||
}
|
||||
)
|
||||
q.push({.now=i, .step=front.step, .used_k = front.used_k+1, .score=front.score,.vis=front.vis ,DEBUG(.his=old_his)});
|
||||
}
|
||||
}
|
||||
std::cout<<ans<<'\n';
|
||||
DEBUG(
|
||||
std::cout<<'\n';
|
||||
std::cout<<last_state<<'\n';
|
||||
)
|
||||
}
|
77
src/test.cpp
77
src/test.cpp
@ -1,77 +1,10 @@
|
||||
#include <type_traits>
|
||||
#define NDEBUG
|
||||
#include <functional>
|
||||
#include <queue>
|
||||
|
||||
#include <iostream>
|
||||
#ifndef NDEBUG
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#define NV(v)#v<<" : "<<(v)
|
||||
using ull = unsigned long long;
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define ARR_NDB_NOEXCEPT noexcept
|
||||
#define ARR_NDB_CONSTEXPR constexpr
|
||||
#else
|
||||
#define ARR_NDB_CONSTEXPR
|
||||
#define ARR_NDB_NOEXCEPT
|
||||
#endif
|
||||
|
||||
template<size_t a,size_t b>
|
||||
constexpr bool test(){
|
||||
return a>=b;
|
||||
bool cmp(const int a,const int b){
|
||||
return a>b;
|
||||
}
|
||||
|
||||
template<class T, size_t size>
|
||||
class Array{
|
||||
public:
|
||||
private:
|
||||
T arr[size];
|
||||
public:
|
||||
ARR_NDB_CONSTEXPR T& operator[](const size_t n)ARR_NDB_NOEXCEPT{
|
||||
#ifndef NDEBUG
|
||||
if(n>=size){
|
||||
std::stringstream ss;
|
||||
ss<<"\nYour [array size] is: "<<size<<"\nBut your [index] is :"<<n<<'\n';
|
||||
throw std::range_error(ss.str());
|
||||
}
|
||||
#endif
|
||||
return arr[n];
|
||||
}
|
||||
ARR_NDB_CONSTEXPR const T& operator[](const size_t n)const ARR_NDB_NOEXCEPT{
|
||||
#ifndef NDEBUG
|
||||
if(n>=size){
|
||||
std::stringstream ss;
|
||||
ss<<"\nYour [array size] is: "<<size<<"\nBut your [index] is :"<<n<<'\n';
|
||||
throw std::range_error(ss.str());
|
||||
}
|
||||
#endif
|
||||
return arr[n];
|
||||
}
|
||||
ARR_NDB_CONSTEXPR operator const T*()const ARR_NDB_NOEXCEPT{
|
||||
return arr;
|
||||
}
|
||||
constexpr bool is_const()const{
|
||||
return true;
|
||||
}
|
||||
constexpr bool is_const(){
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr size_t size {10};
|
||||
constexpr Array<ull,size> arr{};
|
||||
ull a;
|
||||
|
||||
int main(){
|
||||
std::cout<<NV(arr)<<'\n';
|
||||
// std::cout<<NV(&arr[size-1])<<'\n'<<NV(&a)<<'\n';
|
||||
// std::cout<<NV(a)<<'\n';
|
||||
// std::cout<<NV(++arr[size])<<'\n';
|
||||
// std::cout<<NV(a)<<'\n';
|
||||
constexpr ull a {arr[size-1]};
|
||||
const constexpr ull *p {arr};
|
||||
std::cout<<NV(a)<<'\n'<<NV(p)<<'\n';
|
||||
throw std::runtime_error("test");
|
||||
std::priority_queue<int,std::deque<int>,std::less<int>> q;
|
||||
}
|
Loading…
Reference in New Issue
Block a user