QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713893#8056. Travel 2frankly6TL 1ms3628kbC++172.4kb2024-11-05 20:50:052024-11-05 20:50:05

Judging History

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

  • [2024-11-05 20:50:05]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3628kb
  • [2024-11-05 20:50:05]
  • 提交

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, c=1;
        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]=c;
            if(!vis[now]) //add tree edge
            {
                vis[now]=1;
                fa[now]=pre;
                // cout << "now=" << 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();
                c=id[now];
                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: 100
Accepted
time: 1ms
memory: 3628kb

input:

2
1 1
2 1
1 1
Correct
1 3
2 2
1 3
2 2
4 2
1 3
3 1
1 3
4 2
2 2
1 3
Correct

output:

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

result:

ok correct! (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

1000
1 9
2 7
1 9
2 7
3 9
1 9
3 9
4 9
1 9
4 9
3 9
4 9
7 7
1 9
5 8
1 9
5 8
8 8
1 9
6 9
1 9
6 9
2 7
10 6
1 9
7 7
4 9
7 7
8 8
5 8
8 8
10 6
2 7
10 6
8 8
9 8
1 9
8 8
7 7
5 8
9 8
3 9
9 8
5 8
2 7
6 9
10 6
4 9
10 6
6 9
5 8
3 9
2 7
3 9
5 8
6 9
8 8
3 9
10 6
3 9
8 8
6 9
3 9
7 7
3 9
6 9
9 8
2 7
5 8
7 7
9 8
8 8
9...

output:

> 1
> 1
> 1
> 2
> 1
> 2
> 2
> 1
> 3
> 2
> 2
> 3
> 1
> 4
> 1
> 4
> 2
> 1
> 5
> 1
> 5
> 2
> 3
> 1
> 6
> 2
> 3
> 3
> 2
> 2
> 3
> 2
> 3
> 3
> 4
> 1
> 7
> 5
> 4
> 3
> 2
> 3
> 3
> 4
> 4
> 3
> 4
> 4
> 5
> 4
> 5
> 4
> 2
> 5
> 6
> 5
> 6
> 6
> 6
> 7
> 7
> 6
> 8
> 5
> 9
> 7
> 4
> 5
> 7
> 6
> 5
> 4
> 6
> 7
> 8
...

result: