update
This commit is contained in:
parent
fc5edbb714
commit
3ae73e6e4b
@ -1,39 +1,71 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
using std::cin,std::cout,std::iostream;
|
using std::cin,std::cout,std::iostream;
|
||||||
static const constexpr auto range {std::ranges::views::iota};
|
static const constexpr auto range {std::ranges::views::iota};
|
||||||
|
|
||||||
static const constexpr int MOD {80112002}, MAX_TYPES {(int)5e3+5}, MAX_REL_SHIPS {(int)5e5+5};
|
static const constexpr int MOD {80112002}, MAX_TYPES {(int)5e3+5} /*, MAX_REL_SHIPS {(int)5e5+5}*/;
|
||||||
static int types, rel_ships, a, b, in_degree[MAX_REL_SHIPS], out_degree[MAX_REL_SHIPS];
|
static int types, rel_ships, a, b, in_degree[MAX_TYPES], out_degree[MAX_TYPES], link_nums[MAX_TYPES], ans;
|
||||||
std::queue<int> q;
|
static std::queue<int> q;
|
||||||
std::vector<int> next[MAX_REL_SHIPS];
|
static std::vector<int> next[MAX_TYPES];
|
||||||
|
|
||||||
|
class ReadInt{
|
||||||
|
char c;
|
||||||
|
int w,n;
|
||||||
|
public:
|
||||||
|
ReadInt &operator>>(int &num){
|
||||||
|
c=0,w=1,n=0;
|
||||||
|
while(!isdigit(c)){
|
||||||
|
if(c=='-')w=-1;
|
||||||
|
c = (char)getchar();
|
||||||
|
}
|
||||||
|
while(isdigit(c)){
|
||||||
|
n=n*10+(c-'0');
|
||||||
|
c = (char)getchar();
|
||||||
|
}
|
||||||
|
num = n*w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static ReadInt readint;
|
||||||
|
|
||||||
|
#define cin readint
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
iostream::sync_with_stdio(false);
|
|
||||||
|
|
||||||
cin>>types>>rel_ships;
|
cin>>types>>rel_ships;
|
||||||
for(const int _:range(1,rel_ships+1)){
|
for([[maybe_unused]] const int _:range(1,rel_ships+1)){
|
||||||
cin>>a>>b;
|
cin>>a>>b;
|
||||||
next[a].push_back(b);
|
next[a].push_back(b);
|
||||||
in_degree[b]++;
|
in_degree[b]++;
|
||||||
out_degree[a]++;
|
out_degree[a]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const int i:range(1, rel_ships+1)){
|
for(const int i:range(1, types+1)){
|
||||||
if(in_degree[i]==0){
|
if(in_degree[i]==0){
|
||||||
q.push(i);
|
q.push(i);
|
||||||
|
link_nums[i] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(q.empty()==false){
|
while(!q.empty()){
|
||||||
auto front {q.front()};
|
auto front {q.front()};
|
||||||
q.pop();
|
q.pop();
|
||||||
for(auto i:next[front]){
|
for(auto i:next[front]){
|
||||||
|
link_nums[i] = (link_nums[i] + link_nums[front])%MOD;
|
||||||
if(--in_degree[i]==0){
|
if(--in_degree[i]==0){
|
||||||
q.push(i);
|
q.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(auto i:range(1,types+1)){
|
||||||
|
if(out_degree[i]==0){
|
||||||
|
ans = (ans + link_nums[i]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<ans<<"\n";
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user