QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202924 | #7503. Too Many Edges | ucup-team004# | WA | 1ms | 4636kb | C++20 | 1.2kb | 2023-10-06 14:09:37 | 2023-10-06 14:09:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define pb push_back
const int N=50005,M=100005;
int n,m,s[M],t[M],di[N],lst[N],vis[M],l,r,q[N],rd[N];
vector<int> v[N];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin>>n>>m;
For(i,1,m){
cin>>s[i]>>t[i];
v[s[i]].pb(i);
rd[t[i]]++;
}
For(i,1,n)if(!rd[i])q[++r]=i;
while(l<r){
int x=q[++l];
for(auto i:v[x])if(--rd[t[i]]==0){
q[++r]=t[i];
}
}
while(1){
For(i,1,n)lst[i]=di[i]=0;
For(i,1,n){
int x=q[i];
for(auto j:v[x])if(!vis[j]&&di[t[j]]<=di[x]){di[t[j]]=di[x]+1; lst[t[j]]=j;}
}
int p=1;
For(i,2,n)if(di[i]>di[p])p=i;
int i=p;
for(;i;i=s[lst[i]]){
if(lst[i]){
cout<<"? "<<s[lst[i]]<<" "<<i<<endl;
int t;
cin>>t;
if(t==0){
vis[lst[i]]=1;
break;
}
}
}
if(i==0){
cout<<di[p]<<endl; return 0;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4636kb
input:
5 5 1 2 1 3 2 5 3 4 4 5 1 0 1 1
output:
? 4 5 ? 3 4 ? 2 5 ? 1 2 2
result:
wrong answer Output format wrong