QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#163040 | #7107. Chaleur | ucup-team134 | AC ✓ | 300ms | 17524kb | C++14 | 4.0kb | 2023-09-03 19:17:54 | 2023-09-03 19:17:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
typedef pair<ll,ll> pii;
const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=1e5+10;
vector<int>vect[maxn];
int deg[maxn],cnt[maxn],cnt2[maxn];
int n,m;
bool srt(int a,int b){
return deg[a]<deg[b] || (deg[a]==deg[b] && cnt[a]<cnt[b]);
}
void rerun(int &css,vector<pii>cand,vector<int>a){
css=1;
for(int i=1;i<=n;i++){
deg[i]=n-1-deg[i];
cnt[i]=0;
cnt2[i]=0;
}
reverse(a.begin(),a.end());
cand.clear();
cand.pb({0,0});
for(int i=1;i<n;i++){
if(deg[a[i]]==deg[a[i-1]]){
cand[cand.size()-1].ss++;
}
else cand.pb({i,i});
}
for(int i=1;i<=n;i++){
sort(vect[i].begin(),vect[i].end(),srt);
for(int j=0;j<vect[i].size();j++){
if(deg[i]<=deg[vect[i][j]]){
cnt[i]--;
}
if(deg[i]<deg[vect[i][j]]){
cnt2[i]--;
}
}
}
int c=0;
for(int i=cand.size()-1;i>=0;i--){
int l=cand[i].ff;
int r=cand[i].ss;
for(int j=l;j<=r;j++){
cnt[a[j]]+=c+r-l;
cnt2[a[j]]+=c;
}
int e=1;
for(int j=l;j<=r;j++)
if(cnt[a[j]]<c+r-l)e=0;
if(e){
c+=r-l+1;
continue;
}
if( deg[a[r]]<c ){
css=1;
if(deg[a[r]]!=c-1)break;
for(int j=l;j<=r;j++){
if(cnt2[a[j]]==c-1)css++;
}
}
else css=c+r-l+1-deg[a[r]];
break;
}
}
int main() {
/// freopen("test2.txt","r",stdin);
int q;
scanf("%d",&q);
while(q--){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
deg[i]=0;
vect[i].clear();
cnt[i]=0;
cnt2[i]=0;
}
for(int i=1;i<=m;i++){
int u,v;
scanf("%d %d",&u,&v);
vect[u].pb(v);
vect[v].pb(u);
deg[u]++;
deg[v]++;
}
for(int i=1;i<=n;i++){
sort(vect[i].begin(),vect[i].end(),srt);
for(int j=0;j<vect[i].size();j++){
if(deg[i]<=deg[vect[i][j]]){
cnt[i]++;
}
if(deg[i]<deg[vect[i][j]]){
cnt2[i]++;
}
}
}
vector<int>a(n);
for(int i=1;i<=n;i++)
a[i-1]=i;
sort(a.begin(),a.end(),srt);
vector<pii>cand;
cand.pb({0,0});
for(int i=1;i<n;i++){
if(deg[a[i]]==deg[a[i-1]]){
cand[cand.size()-1].ss++;
}
else cand.pb({i,i});
}
int c=0;
int css=1;
for(int i=cand.size()-1;i>=0;i--){
int l=cand[i].ff;
int r=cand[i].ss;
int e=1;
for(int j=l;j<=r;j++)
if(cnt[a[j]]<c+r-l)e=0;
if(e){
c+=r-l+1;
continue;
}
if( deg[a[r]]<c ){
css=1;
if(deg[a[r]]!=c-1)break;
for(int j=l;j<=r;j++){
if(cnt2[a[j]]==c-1)css++;
}
}
else css=c+r-l+1-deg[a[r]];
break;
}
int css2=0;
rerun(css2,cand,a);
printf("%d %d\n",css,css2);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5956kb
input:
3 3 2 1 2 2 3 6 6 1 2 2 3 1 3 1 4 2 5 3 6 4 1 1 2
output:
2 1 1 4 1 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 300ms
memory: 17524kb
input:
2231 1 0 5 7 4 1 3 4 3 1 3 5 4 2 3 2 4 5 5 4 2 1 2 5 2 4 2 3 5 10 3 2 2 5 1 4 4 2 4 5 1 2 1 3 3 5 3 4 1 5 5 10 1 3 2 4 1 4 5 2 2 3 1 5 5 4 1 2 3 4 5 3 5 9 2 5 3 5 2 3 2 1 4 3 3 1 4 1 4 5 2 4 5 4 4 2 4 1 4 5 4 3 5 9 4 1 4 5 3 4 2 4 2 1 3 1 2 5 3 5 3 2 5 4 2 5 2 3 2 1 2 4 5 9 5 2 1 3 4 3 1 2 5 4 4 2 5...
output:
1 1 3 1 4 1 1 5 1 5 2 1 4 1 2 1 4 1 2 1 2 1 3 1 4 1 4 1 1 5 2 1 4 1 1 5 1 5 1 5 3 1 4 1 4 1 4 1 3 1 3 1 4 1 4 1 2 1 4 1 4 1 1 5 1 5 2 1 4 1 4 1 4 1 3 1 2 1 4 1 2 1 4 1 4 1 4 1 3 1 1 5 4 1 4 1 1 5 2 1 4 1 2 1 2 1 1 5 4 1 1 5 3 1 4 1 1 5 2 1 1 5 3 1 3 1 1 5 3 1 3 1 2 1 1 5 4 1 3 1 1 5 2 1 3 1 2 1 2 1 ...
result:
ok 2231 lines
Extra Test:
score: 0
Extra Test Passed