QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168511 | #7107. Chaleur | do_while_true | AC ✓ | 86ms | 9300kb | C++20 | 3.5kb | 2023-09-08 16:29:03 | 2023-09-08 16:29:04 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
const int N=100010;
int n,m;
vi eg[N];
int d[N],p[N];
int vis[N],ban[N],to[N],ok[N],ti[N];
void solve(){
read(n,m);
for(int i=1;i<=n;i++)vi().swap(eg[i]),d[i]=0,p[i]=i,vis[i]=0;
for(int i=1,u,v;i<=m;i++){
read(u,v);eg[u].pb(v);eg[v].pb(u);
++d[u];++d[v];
}
sort(p+1,p+n+1,[&](const int &x,const int &y){return d[x]>d[y];});
for(int i=1;i<n;i++){
int x=p[i],s=0;
for(auto v:eg[x])if(vis[v])++s;
if(s==i-1)
vis[x]=1;
}
int fl=1;
for(int i=1;i<=n;i++)
if(!vis[i]){
for(auto v:eg[i]){
if(!vis[v])
fl=0;
}
}
if(!fl){
puts("1 1");
return ;
}
int tc=0;
for(int i=1;i<=n;i++)if(vis[i])tc++;
for(int i=1;i<=n;i++)ok[i]=ban[i]=to[i]=0;
for(int x=1;x<=n;x++)
if(vis[x]){
int s=0;
for(auto v:eg[x])
if(!vis[v])
++s;
if(s==0)ok[x]=1;
else if(s>1)ban[x]=1;
else{
for(auto v:eg[x])
if(!vis[v])
to[x]=v;
}
}
vi vec;for(int i=1;i<=n;i++)if(vis[i])vec.pb(i),ti[i]=0;
for(int x=1;x<=n;x++)
if(!vis[x]){
if((int)eg[x].size()>=tc-1){
int s=0;
for(auto v:eg[x])if(vis[v])++s;
if(s==tc)ok[x]=1;
else if(s<tc-1)ban[x]=1;
else{
for(auto v:eg[x])if(vis[v])ti[v]=x;
for(auto v:vec)if(ti[v]!=x)to[x]=v;
}
}
}
int l=0,r=0;
for(int i=1;i<=n;i++)
if(ok[i]){
if(vis[i])++l;
else ++r;
}
if(r)cout<<r<<' ';
else{
int s=0;
for(int i=1;i<=n;i++)
if(ok[i]||to[i]){
if(!vis[i])++s;
}
cout<<s+1<<' ';
}
if(l)cout<<l<<'\n';
else{
int s=0;
for(int i=1;i<=n;i++)
if(ok[i]||to[i]){
if(vis[i])++s;
}
cout<<s+1<<'\n';
}
}
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
// assert(freopen("1.out","w",stdout));
#endif
int T;read(T);
while(T--)solve();
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6800kb
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: 86ms
memory: 9300kb
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