QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#158358 | #7107. Chaleur | ucup-team918# | AC ✓ | 816ms | 237564kb | C++20 | 3.0kb | 2023-09-02 16:27:18 | 2023-09-02 16:27:19 |
Judging History
answer
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define ld long double
#define ls (rt<<1)
#define rs ((rt<<1)|1)
#define SZ(x) (int)(x.size())
#define debug cout<<endl<<"ff"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define fi first
#define se second
#define INF 1e9
#define pq priority_queue
#define rep(x,a,b) for(int x=a;x<=b;x++)
/*int fac[N],ifac[N];
int C(int n,int m){
if(m>n||m<0||n<0) return 0;
return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
void init(){
fac[0]=1;
for(int i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
ifac[N-1]=qpow(fac[N-1],mod-2);
for(int i=N-2;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}*/
/*struct node{
int nxt,to;
}e[N<<1];
int cnt=1,head[N];
inline void add(int x,int y){
e[++cnt].nxt=head[x];
head[x]=cnt;
e[cnt].to=y;
}*/
inline int lowbit(int x){return x&(-x);}
inline int read(){
int x=0,t=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') t=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch-'0');
ch=getchar();
}
return x*t;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>=10) write(x/10);
putchar(x%10+'0');
}
int m,T,n,deg[N],dp[N][452],fl[N],in[N];
bool pre[N][452];
vector<int>g[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
cin>>n>>m;
for(int i=0;i<=n;i++) deg[i]=0,g[i].clear(),in[i]=fl[i]=0;
for(int i=1;i<=m;i++){
int x,y;cin>>x>>y;
deg[x]++;deg[y]++;
g[x].pb(y);g[y].pb(x);
}
if(n==1){
cout<<"1 1\n";
continue;
}
dp[0][0]=m;int w=(int)sqrt(2*m)+2;
for(int i=1;i<=w;i++) dp[0][i]=-INF;
for(int i=1;i<=n;i++){
int lim=min(i,w);
for(int j=0;j<=lim;j++) dp[i][j]=-INF;
for(int j=0;j<=lim;j++){
if(dp[i-1][j]<j*(j-1)/2) continue;
if(dp[i-1][j]>dp[i][j+1]){
dp[i][j+1]=dp[i-1][j];
pre[i][j+1]=1;
}
if(dp[i-1][j]-deg[i]>dp[i][j]){
dp[i][j]=dp[i-1][j]-deg[i];
pre[i][j]=0;
}
}
}//1表示i在左边点
int s1=0,s2=0,fl1=0,fl2=0;
int now=-1;
for(int i=min(n,w);i>=0;i--)
if(dp[n][i]==i*(i-1)/2){
now=i;
break;
}
assert(now!=-1);
int tmp=now;
for(int i=n;i>=1;i--){
fl[i]=pre[i][now];
now-=fl[i];
}
/*for(int i=1;i<=n;i++){
if(fl[i]==0){
for(auto t:g[i])
assert(fl[t]==1);
}else{
int sum=0;
for(auto t:g[i])
sum+=fl[t];
assert(sum==tmp-1);
}
}*/
for(int i=1;i<=n;i++){
if(fl[i]==0&°[i]==tmp)
fl1=1;
if(fl[i]==1&°[i]==tmp-1)
fl2=1;
}
if(fl1==0) s1=1;
if(fl2==0) s2=1;
for(int i=1;i<=n;i++){
if(fl1==1){
if(fl[i]==0&°[i]==tmp)
s1++;
}else{
if(fl[i]==0&°[i]==tmp-1)
s1++;
}
if(fl2==1){
if(fl[i]==1&°[i]==tmp-1)
s2++;
}else{
if(fl[i]==1&°[i]==tmp)
s2++;
}
}
cout<<s1<<" "<<s2<<'\n';
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8292kb
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: 816ms
memory: 237564kb
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