D. Valid BFS? time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The BFS algorithm is defined as follows. Consider an undirected graph with vertices numbered from 11 to nn. Initialize qq as a…
比赛的时候想到怎么做了 没调出来(感觉自己是个睿智) 给你N个点M条边,这M条边是一条一条加进去的 要求你求出加入每一条边时图中极大'K度'子图的大小 极大'K度'子图的意思是 要求出一个有尽量多的点的子图 该图中每个点的度数至少为K 因为他每加一条边只会影响到两个点的度数 所以很明显下一个极大'K度'子图是在上一个的基础上得来的 所以如果我们知道在最早哪一步加入边时 产生了极大'K度'子图的话 我们就可以对每条边进行判定得出答案 但是如果每一步都判是否有极大'K度'子图 肯定会超时 该题是离线…
https://codeforces.com/contest/1037/problem/F 题意 function z(array a, integer k): if length(a) < k: return 0 else: b = empty array ans = 0 for i = 0 .. (length(a) - k): temp = a[i] for j = i .. (i + k - 1): temp = max(temp, a[j]) append temp to the en…
https://codeforces.com/contest/1037/problem/E 题意 有n个人,m天,在第i天早上,x和y会成为朋友,每天晚上大家都要上车,假如一个人要上车那么他得有至少k个朋友上车,输出每天晚上上车人数 题解 一个点的度数<k,他就上不了车 假如一个人上不了车,那么他对他的朋友就没有了价值,就等于把边去掉 离线处理,反着消边 因为每条边只能走一次,所以标记边bfs 代码 #include<bits/stdc++.h> #define MAXN 200005…
C - Equalize #include<bits/stdc++.h> using namespace std; using namespace std; string a,b; int main(){ int n; cin>>n; cin>>a>>b; ,sum=; ;j<n;j++){ if(a[j]!=b[j]) ans++; } ;j<n-;j++){ if(a[j]==b[j]) continue; ]==]=='){ sum++;…
还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cstring> #include <stack> #include <set> using namespace std; ],v[],n,m,k,ans; ],vis[]; ]; stack<int> S; void dfs(int u){ if(sons[u].size…
随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <queue> using namespace std; ],v[],fir[],nxt[],cnt=,dep[],squ[]; ]; void addedge(int ui,int vi){ cnt++; u[cnt]=ui; v[c…
是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <map> using namespace std; ],b[],f[]; ],bx[]; int main(){ scanf("%d",&n); scanf(); scanf(); ;i&…
题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ,n,s,a[]; int main(){ scanf("%I64d %I64d",&n,&s); ;i<=n;i++) scanf("%I64d&quo…
就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; int main(){ int n; scanf("%d",&n); ,ans=,now=; while(i<n){ i+=now*; now*=;…