QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713843#8056. Travel 2frankly6TL 0ms0kbC++172.3kb2024-11-05 20:41:232024-11-05 20:41:23

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 20:41:23]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-05 20:41:23]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
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);
    cin >> T;
    while(T--)
    {  
        cnt=0;
        int now=0, num=0, pre=0, nm=0;
        cin >> now >> num;
        siz[now]=num;
        cout << "> " << ++id[now] << '\n';
        cout.flush();
        pre=now, nm=num; vis[1]=1;
        while(1)
        {
            cin >> now >> num;
            siz[now]=num;
            k[pre][now]=nm;
            if(!vis[now]) //add tree edge
            {
                vis[now]=1;
                fa[now]=pre;
            }
            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 << " "; 
            fa[u]=fa[v]=0;
            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';
        cout.flush();
        string s;
        cin >> s;
    }
    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
Correct
1 3
2 2
1 3
4 2
1 3
4 2
2 2
4 2
2 2
4 2
2 2
4 2
2 2
4 2
2 2
4 2
2 2
4 2

output:

> 1
> 1
! 2 1 
> 1
> 1
> 3
> 1
> 3
> 2
> 2
> 2
> 2
> 2
> 2
> 2
> 2
> 2
> 2
> 2
> 2
> 2

result: