QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#224349 | #7503. Too Many Edges | FEDIKUS | TL | 2ms | 7364kb | C++14 | 1.5kb | 2023-10-23 01:29:12 | 2023-10-23 01:29:13 |
Judging History
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){
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: 7364kb
input:
5 5 1 2 1 3 2 5 3 4 4 5 1 0
output:
? 4 5 ? 3 4 ! 2
result:
ok Correct answer
Test #2:
score: -100
Time Limit Exceeded
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 ...