QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#409079 | #6414. Classical Maximization Problem | ciuim | WA | 0ms | 16180kb | C++14 | 2.2kb | 2024-05-11 17:40:14 | 2024-05-11 17:40:15 |
Judging History
answer
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#define ll long long
#define db double
#define ull unsigned long long
#define reg register
#define fo(a,b,c) for(reg ll a=b;a<=c;++a)
#define re(a,b,c) for(reg ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<node> ::iterator
using namespace std;
const ll mod=998244353;
inline ll gi()
{
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x * f;
}
ll _=1;
const ll inf=1e17+5;
const ll N=500005;
ll n,cnt=0,vis[N],use[N];
map<ll,ll> mp1,mp2;
vector<pii> g[N],ans;
void dfs(ll u,ll fa)
{
vis[u]=1;
for(pii p:g[u])
{
ll v=p.fi;
if(vis[v]) continue;
dfs(v,u);
}
ll las=0,f=0;
for(pii p:g[u])
{
if(use[p.se]) continue;
ll v=p.fi;
if(v==fa) f=p.se;
else
{
if(las) ans.pb({las,p.se}),las=0,use[las]=use[p.se]=1;
else las=p.se;
}
}
if(f&&las)
{
use[f]=use[las]=1;
ans.pb({f,las});
}
}
void sol()
{
ans.clear();
cnt=0;
mp1.clear();
mp2.clear();
n=gi();
fo(i,1,2*n)
{
ll x=gi(),y=gi();
if(!mp1[x])
{
cnt++;
mp1[x]=cnt;
}
if(!mp2[y])
{
cnt++;
mp2[y]=cnt;
}
x=mp1[x],y=mp2[y];
g[x].pb({y,i});
g[y].pb({x,i});
}
fo(i,1,cnt)
{
if(vis[i]==0)
{
dfs(i,0);
}
}
cout<<ans.size()<<'\n';
for(pii p:ans)
{
cout<<p.fi<<" "<<p.se<<'\n';
}
vector<ll> vec;
fo(i,1,2*n)
{
if(use[i]==0) vec.pb(i);
}
ll sz=vec.size();
for(ll i=0;i<sz;i+=2)
{
cout<<vec[i]<<" "<<vec[i+1]<<'\n';
}
fo(i,0,cnt)
{
vis[i]=0;
g[i].clear();
}
fo(i,0,2*n) use[i]=0;
}
int main()
{
_=gi();
while(_--)
{
sol();
// printf("\n");
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 16180kb
input:
3 2 0 0 0 1 1 0 1 1 2 0 0 0 1 0 2 0 3 2 0 0 1 1 2 2 3 3
output:
2 4 2 1 3 2 1 2 3 4 1 3 0 1 2 3 4
result:
wrong answer Integer parameter [name=b[1]] equals to 0, violates the range [1, 4] (test case 3)