QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#817193 | #9880. Origami Warp | Afterlife# | WA | 0ms | 3812kb | C++20 | 3.5kb | 2024-12-16 20:51:46 | 2024-12-16 20:51:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=4004;
int n,m,dep[N],f[N];
vector<pair<int,int> > G[N];
ull h[N];
mt19937_64 rnd(233);
bool vis[N];
ull he[N],hn[N];
void dfs1(int u,int fa){
f[u]=fa;
vis[u]=1;
for(auto [v,id]:G[u]){
if(v==fa)continue;
if(vis[v]){
if(dep[v]<dep[u]){
he[u]^=h[id];
he[v]^=h[id];
hn[u]^=h[id];
hn[f[v]]^=h[id];
}
continue;
}
dep[v]=dep[u]+1;
dfs1(v,u);
he[u]^=he[v];
hn[u]^=hn[v];
}
//cerr<<" ?? "<<u<<" "<<he[u]<<" "<<hn[u]<<endl;
}
int o;
void dfs2(int u){
if(o)return;
for(auto [v,id]:G[u]){
if(v==f[u])continue;
if(f[v]==u){
if(he[v]==0){
if(hn[u]==hn[v]){
o=id;
return;
}
}
else{
bool ok=1;
ull qwq=he[v];
for(auto [z,id]:G[u]){
if(f[z]==u){
if(he[z]&&he[z]^qwq){
ok=0;
}
}
else if(f[u]==z){
if(he[u]&&he[u]^qwq){
ok=0;
}
}
}
for(auto [z,id]:G[v]){
if(f[z]==v){
if(he[z]&&he[z]^qwq){
ok=0;
}
}
else if(f[v]==z){
if(he[v]&&he[v]^qwq){
ok=0;
}
}
}
if(ok){
o=id;
return;
}
}
}
else{
if(hn[u]==hn[v]&&hn[u]==h[id]){
o=id;
return;
}
}
dfs2(v);
}
}
int x[N],y[N];
int Find(){
for(int i=1;i<=n;++i)vis[i]=dep[i]=he[i]=hn[i]=f[i]=0;
o=0;
for(int i=1;i<=n;++i){
if(vis[i])continue;
dfs1(i,0);
dfs2(i);
if(o){
for(auto it=G[x[o]].begin();it!=G[x[o]].end();++it){
if(it->first==y[o]){
G[x[o]].erase(it);
break;
}
}
for(auto it=G[y[o]].begin();it!=G[y[o]].end();++it){
if(it->first==x[o]){
G[y[o]].erase(it);
break;
}
}
return o;
}
}
return -1;
}
void Solve(){
cin>>n>>m;
for(int i=1;i<=n;++i){
G[i].clear();
}
for(int i=1;i<=m;++i){
h[i]=rnd();
}
for(int i=1;i<=m;++i){
int u,v;
cin>>u>>v;
x[i]=u,y[i]=v;
G[u].emplace_back(v,i);
G[v].emplace_back(u,i);
}
vector<int> ans;
for(int t=1;t<=m;++t){
int x=Find();
if(x==-1){
cout<<-1<<'\n';
return;
}
ans.push_back(x);
}
reverse(ans.begin(),ans.end());
for(auto x:ans){
cout<<x<<' ';
}
cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)Solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
2 3 0 0 1 0 0 0 0 1 0 2 2 0 4 1 0 2 3 1 -2 -1 2 1 1 -1 0 3 3 3 3 3 0 0 1 0 0 0 0 1 -2 1 2 3 2 2 1 -1 5 -1 -1 3 3
output:
-1
result:
wrong output format YES or NO expected, but -1 found [1st token]