diff --git a/src/7/15/U306735.cpp b/src/7/15/U306735.cpp new file mode 100644 index 0000000..d7c42bf --- /dev/null +++ b/src/7/15/U306735.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include + +using ll=int64_t; + +ll n{},m{}; +std::string s; +std::vector> edge; + +ll find(ll now,std::map &w,ll max,std::vector &vis){ + if(vis[now]){ + return -1; + } + vis[now]=true; + w[s[now]]++; + max=std::max(max,w[s[now]]); + for(ll nxt:edge[now]){ + if(ll findr = find(nxt, w,max,vis);findr==-1){ + return -1; + }else{ + max=std::max(max,findr); + } + } + w[s[now]]--; + vis[now]=false; + return max; +} + +int main(){ + std::iostream::sync_with_stdio(false); + std::cin.tie(nullptr); + std::cout.tie(nullptr); + + std::cin>>n>>m; + edge.resize(n+1); + std::cin>>s; + s=' '+s; + for(ll i=1;i<=m;i++){ + ll u{},v{}; + std::cin>>u>>v; + edge[u].push_back(v); + } + + for(ll i=1;i<=n;i++){ + ll ans{}; + std::map w; + std::vector vis(n+1); + ans=find(i, w, 0,vis); + std::cout<