QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#713791 | #8056. Travel 2 | frankly6 | TL | 0ms | 0kb | C++17 | 2.2kb | 2024-11-05 20:33:43 | 2024-11-05 20:33:43 |
answer
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
typedef pair<int,int> PII;
const int MX=2550;
const int MZ=10000;
int T, N, M, cnt;
int id[MX], siz[MX], fa[MX], tag[MX];
bool g[MX][MX];
int k[MX][MX], vis[MX];
PII ans[MZ];
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
int main()
{
// freopen("testdata.in","r",stdin);
T=read();
while(T--)
{
cnt=0;
int now=0, num=0, pre=0, nm=0;
now=read(); num=read();
siz[now]=num;
cout << "> " << ++id[now] << '\n';
cout.flush();
pre=now, nm=num; vis[1]=1;
while(1)
{
now=read(); num=read();
siz[now]=num;
k[pre][now]=nm;
if(!vis[now]) //add tree edge
{
vis[now]=1;
fa[now]=pre;
// cout << "u=" << now << ", fa=" << pre << '\n';
}
if(id[now]==siz[now]) //full size return
{
// cout << "siz\n";
if(now==1) break;
tag[now]=1;
cout << "> " << k[now][fa[now]] << '\n';
cout.flush();
}
else if(fa[pre]==now&&!tag[pre]) //tree edge return
{
// cout << "tree\n";
cout << "> " << k[now][pre] << '\n';
cout.flush();
}
else //keep search
{
if(!g[now][pre]) g[now][pre]=g[pre][now]=1, ans[++cnt]={now,pre};
cout << "> " << ++id[now] << '\n';
cout.flush();
if(id[now]==siz[now]) tag[now]=1;
}
pre=now, nm=num;
}
cout << "! ";
for(int i=1;i<=cnt;i++)
{
auto [u,v]=ans[i];
cout << u << " " << v << " ";
siz[u]=siz[v]=0;
id[u]=id[v]=0;
tag[u]=tag[v]=0;
vis[u]=vis[v]=0;
g[u][v]=g[v][u]=k[v][u]=k[u][v]=0;
}
cout << '\n';
}
return (0-0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 1 1 2 1 1 1
output:
> 1 > 1