2 questions, 98, T-shirt in hand
Is the real name certification late, I don't know if it will affect.
Upper solution
The king's way of yard team's girlfriend
Simple simulation is enough. Pay attention to the net game. It is possible to pay attention to long long in the course of the season.
The king's way of yard team's girlfriend#include<bits/stdc++.h> #define MAX 105 using namespace std; typedef long long ll; string s; int main() { int t,n,m,i,j,k; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&k,&m); scanf(" "); cin>>s; ll c=0,cc=0,ans=0; for(i=0;i<n;i++){ if(s[i]=='1') c++; else{ if(k>0) k--; else c--; } cc=max(cc,c); } if(c<0) printf("%lld\n",max(0ll,cc)); else printf("%lld\n",max(0ll,c*(m-1)+cc)); } return 0; }
Brother of the code team who taught himself graph theory
First find the odd number ring with dfs, then find the value of the elements in the ring by dichotomy, and finally find the value of the elements outside the ring by bfs.
Brother of the code team who taught himself graph theory#include<bits/stdc++.h> #define MAX 100005 using namespace std; typedef long long ll; vector<int> v[MAX],vv,vvv; map<int,map<int,int> > mp; queue<int> q; int a[MAX],b[MAX],bb[MAX]; int f; void dfs(int pre,int x){ if(f==1) return; for(int i=0;i<v[x].size();i++){ int to=v[x][i]; if(to==pre) continue; if(b[to]){ vv.push_back(to); f=1; return; } b[to]=1; vv.push_back(to); dfs(x,to); if(f==1) return; vv.pop_back(); } } int main() { int t,n,x,y,z,i,j; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%d%d",&x,&y,&z); v[x].push_back(y); v[y].push_back(x); mp[x][y]=z; mp[y][x]=z; } if(n==1){ printf("%d\n",z); return 0; } f=0; b[1]=1; vv.push_back(1); dfs(-1,1); for(i=0;i<vv.size();i++){ if(vv[i]==vv[vv.size()-1]){ for(j=i;j<vv.size();j++){ vvv.push_back(vv[j]); } break; } } // for(i=0;i<vvv.size();i++){ // printf("%d ",vvv[i]); // }printf("\n"); int l=-32768,r=32768,m; while(l<=r){ m=(l+r)/2; int ff=0; a[vvv[0]]=m; for(i=1;i<vvv.size()-1;i++){ a[vvv[i]]=mp[vvv[i-1]][vvv[i]]-a[vvv[i-1]]; if(a[vvv[i]]<-32768&&(i&1)){ ff=1; break; } else if(a[vvv[i]]<-32768&&(i%2==0)){ ff=2; break; } else if(a[vvv[i]]>32768&&(i&1)){ ff=2; break; } else if(a[vvv[i]]>32768&&(i%2==0)){ ff=1; break; } } if(ff==1){ r=m-1; } else if(ff==2){ l=m+1; } else{ int z=mp[vvv[vvv.size()-2]][vvv[vvv.size()-1]]-a[vvv[vvv.size()-2]]; if(z<-32768){ r=m-1; } else if(z>32768){ l=m+1; } else if(a[vvv[0]]==z){ break; } else if(a[vvv[0]]<z){ l=m+1; } else{ r=m-1; } } } for(i=0;i<vvv.size()-1;i++){ q.push(vvv[i]); bb[vvv[i]]=1; } while(q.size()){ int p=q.front(); for(i=0;i<v[p].size();i++){ int to=v[p][i]; if(bb[to]) continue; bb[to]=1; a[to]=mp[p][to]-a[p]; q.push(to); } q.pop(); } for(i=1;i<=n;i++){ printf("%d\n",a[i]); } return 0; } /* 8 1 2 11 2 3 7 2 4 9 4 5 2 4 6 8 5 7 13 6 8 -1 7 8 -2 */