QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708112 | #8056. Travel 2 | Wolam | RE | 0ms | 0kb | C++17 | 2.4kb | 2024-11-03 19:37:13 | 2024-11-03 19:37:15 |
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 3e3 + 10;
int id[maxn][maxn],d[maxn],mx,cnt[maxn],vis[maxn];
vector<pair<int,int>> edge;
void init(void)
{
for(int i=1;i<=mx;i++)
{
vis[i]=0;
cnt[i]=0;
d[i]=0;
for(int j=1;j<=mx;j++)
{
id[i][j]=0;
}
}
mx=0;
edge.clear();
}
int walk(int i)
{
cout<<"> "<<i<<endl;
int v;
cin>>v;
mx=max(mx,v);
cin>>d[v];
return v;
}
void dfs(int u,int pa)
{
if(vis[u]&&pa)
{
if(id[u][pa])
{
walk(id[u][pa]);
}
for(int i=cnt[u]+1;i<=d[u];i=cnt[u]+1)
{
cnt[u]++;
int v=walk(i);
id[u][v]=i;
if(v==pa)
{
return;
}
if(u<v)
edge.emplace_back(u,v);
else
edge.emplace_back(v,u);
if(!vis[v])
{
dfs(v,u);
walk(id[v][u]);
}
else
{
dfs(v,u);
}
}
}
else
{
vis[u]=1;
for(int i=cnt[u]+1;i<=d[u];i=cnt[u]+1)
{
cnt[u]++;
int v=walk(i);
id[u][v]=i;
if(u<v)
edge.emplace_back(u,v);
else
edge.emplace_back(v,u);
if(!vis[v])
{
dfs(v,u);
walk(id[v][u]);
}
else
{
dfs(v,u);
}
}
}
}
void solve(void)
{
init();
int root;
cin>>root;
cin>>d[root];
dfs(root,0);
sort(edge.begin(),edge.end());
edge.erase(unique(edge.begin(),edge.end()),edge.end());
cout<<"! ";
for(int i=0;i<(int)edge.size();i++)
{
cout<<edge[i].first<<" "<<edge[i].second;
if(i==(int)edge.size()-1)
{
cout<<endl;
}
else
{
cout<<" ";
}
}
string s;
cin>>s;
if(s=="Wrong")
{
assert(false);
}
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 1 1 2 1 1 1 2 1 1 1 Correct 1 3 2 2 1 3 2 2 4 2 1 3 3 1
output:
> 1 > 1 > 1 > 1 ! 1 2 > 1 > 1 > 1 > 2 > 1 > 2 > 3