QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#294082 | #7503. Too Many Edges | AlphaMale06 | WA | 1ms | 5912kb | C++14 | 2.3kb | 2023-12-30 05:20:08 | 2023-12-30 05:20:08 |
Judging History
answer
#include <bits/stdc++.h>
/*
Oce nas,
koji si na nebesima,
da se sveti ime Tvoje,
da dodje carstvo Tvoje,
da bude volja Tvoja,
i na zemlji, kao i na nebu.
Hleb nas nasusni daj nam danas,
i oprosti nam dugove nase,
kao sto i mi oprastamo duznicima svojim,
i ne uvedi nas u iskusenje,
no izbavi nas od zloga.
Jer je Tvoje Carstvo,
i sila, i slava,
u vekove vekova.
Amin.
*/
using namespace std;
typedef vector<int> vc;
typedef vector<vector<int>> vvc;
using ll = long long;
using ld = long double;
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 5e4+3;
set<int> adj[N];
int indeg[N];
vector<int> toposorted;
bool mark[N];
int d[N];
int p[N];
int prevans=0;
void dfs(int v){
toposorted.pb(v);
mark[v]=1;
for(auto to =adj[v].begin(); to!=adj[v].end(); to++){
int nd=*to;
if(!mark[nd])dfs(nd);
}
}
void sortbydist(int n){
for(int i=1; i<=n; i++){
if(!indeg[i])dfs(i);
}
for(int v : toposorted){
for(auto to = adj[v].begin(); to!=adj[v].end(); to++){
int nd=*to;
if(d[v]+1>d[nd]){
p[nd]=v;
d[nd]=d[v]+1;
}
}
}
}
void solve(){
int n, m;
cin >> n >> m;
for(int i=0; i< m; i++){
int x, y;
cin >> x >> y;
adj[x].insert(y);
indeg[y]++;
}
int ans=-1;
bool ok=0;
while(true){
prevans=max(prevans, ans);
ok=0;
toposorted.clear();
for(int i=1; i<=n; i++){
d[i]=0;
mark[i]=0;
}
sortbydist(n);
int mx=0;
int mxind=0;
for(int i=1; i<=n; i++){
if(d[i]>=mx){
mx=d[i];
mxind=i;
}
}
vector<int> path;
while(indeg[mxind]!=0){
path.pb(mxind);
mxind=p[mxind];
}
if(path.size()<=prevans){
cout << "! " << prevans << endl;
return;
}
reverse(all(path));
for(int i=0; i< path.size(); i++){
cout << "? " << mxind << " " << path[i] << endl;
bool yes;
cin >> yes;
if(!yes){
ans=i;
adj[mxind].erase(path[i]);
indeg[path[i]]--;
ok=1;
break;
}
mxind=path[i];
}
if(!ok){
prevans=path.size();
break;
}
}
cout << "! " << prevans << endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5912kb
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: 0ms
memory: 5884kb
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 161 ? 161 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 28 ? 28 21 ? 21 218 ? 218 200 ? 200 154 ? 154 225 ? 225 221 ? 221 217 ? 217 134 ? 134 52 ? 5...
result:
wrong answer The answer is incorrect