QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224293#7503. Too Many EdgesStefanSebezWA 3ms6644kbC++142.6kb2023-10-23 01:03:432023-10-23 01:03:44

Judging History

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

  • [2023-10-23 01:03:44]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6644kb
  • [2023-10-23 01:03:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define int long long
const int N=5*1e4+50;
map<pair<int,int>,int>mapa;
vector<int>E[N],E1[N];
int dp[N],parent[N];
bool was[N];
vector<int>topo;
void DFS(int u)
{
    /*for(auto i:E1[u])
    {
        if(i.se==1 && dp[i.fi]+1>dp[u]){dp[u]=max(dp[u],dp[i.fi]+1);parent[u]=i.fi;}
    }*/
    was[u]=true;
    for(auto i:E[u])
    {
        if(mapa[{u,i}] && !was[i])DFS(i);
    }
    topo.pb(u);
}
int ask(int u,int v)
{
    cout<<"? "<<u<<" "<<v<<endl;
    int x;cin>>x;
    return x;
}
signed main()
{
    int n,m;cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;cin>>u>>v;
        E[u].pb(v);
        E1[v].pb(u);
        mapa[{u,v}]=1;
        mapa[{v,u}]=1;
    }
    /*for(int i=1;i<=n;i++)
    {
        sort(E[i].begin(),E[i].end());
        sort(E1[i].begin(),E1[i].end());
    }*/
    int res;
    while(1)
    {
        for(int i=1;i<=n;i++)
        {
            int ct=0;
            for(auto j:E1[i])
            {
                if(mapa[{i,j}]==1) ct++;
            }
            if(ct==0)
            {
                //cout<<i<<endl;
                DFS(i);
                reverse(topo.begin(),topo.end());
                /*for(auto j:topo)cout<<j<<" ";
                cout<<endl;*/
                for(int j=1;j<topo.size();j++)
                {
                    int u=topo[j];
                    for(auto k:E1[u])
                    {
                        if(mapa[{u,k}] && dp[k]+1>dp[u]){dp[u]=max(dp[u],dp[k]+1);parent[u]=k;}
                    }
                }
                topo.clear();
            }
        }
        /*for(int i=1;i<=n;i++)cout<<dp[i]<<" ";
        cout<<endl;
        for(int i=1;i<=n;i++)cout<<parent[i]<<" ";
        cout<<endl;*/
        int ind=1;
        for(int i=1;i<=n;i++)
        {
            if(dp[i]>dp[ind])ind=i;
        }
        vector<int>put;
        int par=parent[ind];
        while(par!=0)
        {
            put.pb(ind);
            ind=par;
            par=parent[par];
        }
        put.pb(ind);
        bool bul=false;
        /*for(auto i:put)cout<<i<<" ";
        cout<<endl;*/
        for(int i=put.size()-1;i>=1;i--)
        {
            int u=put[i],v=put[i-1];
            if(!ask(u,v))
            {
                mapa[{u,v}]=mapa[{v,u}]=0;
                bul=true;
                break;
            }
        }
        if(!bul){res=put.size()-1;break;}
        for(int i=1;i<=n;i++)dp[i]=parent[i]=was[i]=0;
    }
    cout<<"! "<<res<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6644kb

input:

5 5
1 2
1 3
2 5
3 4
4 5
1
0
1
1

output:

? 1 3
? 3 4
? 1 2
? 2 5
! 2

result:

ok Correct answer

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 6084kb

input:

230 470
212 98
107 123
116 72
158 83
135 111
78 123
221 217
214 203
28 221
229 3
111 127
128 13
125 116
180 78
175 191
182 99
194 6
12 83
209 29
169 129
192 208
145 38
33 86
104 85
145 82
38 82
193 153
109 41
199 194
89 72
161 227
36 177
13 141
173 110
212 77
155 81
87 82
104 172
148 182
170 222
68 ...

output:

? 147 145
? 145 53
? 53 178
? 178 223
? 223 101
? 101 195
? 195 38
? 38 81
? 81 207
? 207 87
? 87 82
? 82 137
? 137 196
? 196 15
? 15 113
? 113 20
? 20 40
? 40 227
? 227 224
? 224 56
? 56 175
? 175 167
? 167 176
? 176 211
? 211 112
? 112 62
? 62 135
? 135 198
? 198 201
? 201 131
? 131 191
? 191 205
...

result:

wrong answer The answer is incorrect