QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#339549 | #1844. Cactus | AFewSuns | WA | 2ms | 23904kb | C++14 | 3.3kb | 2024-02-27 15:41:49 | 2024-02-27 15:41:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
vector<pair<ll,ll> > ans;
vector<ll> vec[600060];
queue<ll> q;
ll n,m,head[300030],cnt=0,d[300030];
ll dfn[300030],low[300030],tot=0,st[300030],top=0,tott;
bl ck[600060];
struct node{
ll nxt,to;
}e[1000010];
void add(ll u,ll v){
e[++cnt].nxt=head[u];
e[cnt].to=v;
head[u]=cnt;
}
void tarjan(ll fa,ll u){
dfn[u]=low[u]=++tot;
st[++top]=u;
go(u){
ll v=e[i].to;
if(!dfn[v]){
tarjan(u,v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
tott++;
while(st[top]!=v){
vec[tott].push_back(st[top]);
vec[st[top]].push_back(tott);
top--;
}
vec[tott].push_back(v);
vec[v].push_back(tott);
top--;
vec[tott].push_back(u);
vec[u].push_back(tott);
}
}
else if(v!=fa) low[u]=min(low[u],dfn[v]);
}
}
void dfs(ll fa,ll u){
ck[u]=1;
fr(i,0,(ll)vec[u].size()-1){
ll v=vec[u][i];
if(v==fa) continue;
dfs(u,v);
}
if(u<=n) return;
ll son=0,fir=0,lst=0;
fr(i,0,(ll)vec[u].size()-1){
ll v=vec[u][i];
if(v==fa) continue;
son++;
if(son&1) ans.push_back(MP(1,v));
else ans.push_back(MP(1,v+n));
if(!fir) fir=v;
lst=v;
}
ans.push_back(MP(1,fir+n));
if(son&1) ans.push_back(MP(1,lst+n));
else ans.push_back(MP(1,lst));
}
int main(){
n=read();
m=read();
fr(i,1,m){
ll u=read(),v=read();
vec[u].push_back(v);
vec[v].push_back(u);
d[u]++;
d[v]++;
}
fr(i,1,n) if(d[i]&1) q.push(i);
while(!q.empty()){
ll u=q.front();
q.pop();
if(ck[u]||d[u]%2==0) continue;
ck[u]=1;
ans.push_back(MP(1,u));
fr(i,0,(ll)vec[u].size()-1){
ll v=vec[u][i];
d[v]--;
if(!ck[v]&&(d[v]&1)) q.push(v);
}
}
fr(i,1,n){
if(ck[i]) continue;
fr(j,0,(ll)vec[i].size()-1) if(!ck[vec[i][j]]) add(i,vec[i][j]);
}
fr(i,1,n) vec[i].clear();
tott=n;
fr(i,1,n) if(!dfn[i]) tarjan(0,i);
ans.push_back(MP(2,0));
fr(i,1,n){
if(!ck[i]){
dfs(0,i);
ans.push_back(MP(1,i));
}
}
pf("0 %lld\n",(ll)ans.size());
fr(i,0,(ll)ans.size()-1){
if(ans[i].fir==2) writeln(2);
else pf("1 %lld\n",ans[i].sec);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 23904kb
input:
3 3 1 2 1 3 2 3
output:
0 6 2 1 2 1 6 1 5 1 3 1 1
result:
ok You are right!
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 23772kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 10 1 4 1 5 1 6 1 7 2 1 2 1 10 1 9 1 3 1 1
result:
wrong answer The number of remaining edges is not equal to m'.