QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294088#7503. Too Many EdgesAlphaMale06WA 2ms6020kbC++142.7kb2023-12-30 05:49:522023-12-30 05:49:53

Judging History

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

  • [2023-12-30 05:49:53]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6020kb
  • [2023-12-30 05:49:52]
  • 提交

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];
map<pair<int, int>, int> asked;
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++){
		d[i]=0;
		mark[i]=0;
		p[i]=0;
	}
	queue<int> q;
	for(int i=1; i<=n; i++){
		if(!indeg[i]){
			q.push(i);
			toposorted.pb(i);
		}
	}
	while(!q.empty()){
		int v=q.front();
		q.pop();
		mark[v]=1;
		for(auto to = adj[v].begin(); to!=adj[v].end(); to++){
			int nd=*to;
			if(!mark[nd]){
				q.push(nd);
				toposorted.pb(nd);
			}
		}
	}
	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;
	while(true){
		prevans=max(prevans, ans);
		ok=0;
		toposorted.clear();
		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++){
			bool yes;
			if(!asked[{mxind, path[i]}]){
				cout << "? " << mxind << " " << path[i] << endl;
				cin >> yes;
				asked[{mxind, path[i]}]=1;
			}
			else yes=1;
			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: 5820kb

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: 2ms
memory: 6020kb

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 196
? 196 224
? 224 56
? 56 175
? 175 167
? 167 176
? 176 127
? 127 200
? 200 154
? 154 225
? 225 221
? 221 217
? 217 134
? 134 52
? 52 181
? 181 165
? 165 186
? 186 173
? 173 110
? 110 17
? 17 6
? 6 9
? 9 119
? 119 69
? 69 202
...

result:

wrong answer The answer is incorrect