QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224416#7503. Too Many EdgesFEDIKUSWA 3ms7684kbC++141.5kb2023-10-23 02:24:072023-10-23 02:24:07

Judging History

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

  • [2023-10-23 02:24:07]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7684kb
  • [2023-10-23 02:24:07]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int maxn=5e4+10;

vector<int> g[maxn];
set<int> ne[maxn];
bool bio[maxn];

int n,m;
int t=0;
pair<int,int> ti[maxn];

void dfs(int node){
  bio[node]=true;
  for(int i:g[node]){
    if(bio[i]) continue;
    dfs(i);
  }
  ti[node].first=t++;
}

pair<int,int> dp[maxn]; // duz odavde i ko je sledeci

pair<int,int> naj(){
  for(int i=1;i<=n;i++){
    dp[i]={1,i};
  }
  pair<int,int> najj={0,0};
  for(int i=1;i<=n;i++){
    int node=ti[i].second;
    for(int j:g[node]){
      if(ne[node].find(j)!=ne[node].end()) continue;
      dp[node]=max(dp[node],{dp[j].first+1,j});
    }
    najj=max(najj,{dp[node].first,node});
  }
  return najj;
}

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int u,v; cin>>u>>v;
    g[u].push_back(v);
  }
  for(int i=1;i<=n;i++) ti[i].second=i;
  for(int i=1;i<=n;i++) if(!bio[i]) dfs(i);
  sort(ti+1,ti+n+1);
  while(true){
    pair<int,int> sta=naj();
    int duz=sta.first;
    int node=sta.second;
    vector<int> put;
    put.push_back(node);
    while(node!=dp[node].second){
      put.push_back(dp[node].second);
      node=dp[node].second;
    }
    bool ok=true;
    for(int i=0;i<int(put.size())-1;i++){
      cout<<"? "<<put[i]<<" "<<put[i+1]<<"\n";
      cout.flush();
      int ans; cin>>ans;
      if(ans==1) ok=false;
      if(!ok){
        ne[put[i]].emplace(put[i+1]);
        break;
      }
    }
    if(ok){
      cout<<"! "<<duz<<"\n";
      break;
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7164kb

input:

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

output:

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

result:

ok Correct answer

Test #2:

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

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
? 147 101
? 101 195
? 195 38
? 147 155
? 145 38
? 101 38
? 195 81
? 155 81
? 38 81
? 81 207
? 207 87
? 195 87
? 147 82
? 145 82
? 87 82
? 38 82
? 195 137
? 82 137
? 147 27
? 137 196
? 87 27
? 38 196
? 196 15
? 27 15
? 101 113
? 15 113
? 147 20
? 113 20...

result:

wrong answer The answer is incorrect