This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <limits>
#include <map>
#include <utility>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include<assert.h>
#include <functional>
#include <iterator>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
const int MAXN=3e4+100;
vector<int> v[MAXN];
int k;
int n;
void init(int N, int K) {
n=N;
k=K;
for(int i=0;i<=k-2;i++){
// dbg(i,i+1)
v[i].pb(i+1);
}
}
bool visited[MAXN];
bool check(int a){
return 0<=a&&a<=k-1;
}
bool dfs(int node,int top){
dbg(node,top)
if(visited[node]) {
if(top>=node) return true;
else return false;
}
visited[node]=true;
for(auto x:v[node]){
if(check(node)&&check(x)) {
if(x-node==1) {
if(dfs(x,x)) return true;
}else {
// dbg(x,node,visited[x])
if(dfs(x,node)) return true;
}
}else{
if(dfs(x,top)) return true;
}
}
return false;
}
int add_teleporter(int a, int b) {
v[a].pb(b);
memset(visited,false,sizeof(visited));
bool ok=dfs(0,0);
dbg(ok);
return ok;
}
#ifdef IOI
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "game.h"
namespace {
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
} // namespace
int main() {
int N = read_int();
int M = read_int();
int K = read_int();
std::vector<int> u(M), v(M);
for (int i = 0; i < M; ++i) {
u[i] = read_int();
v[i] = read_int();
}
init(N, K);
int i;
for (i = 0; i < M; ++i) {
int answer = add_teleporter(u[i], v[i]);
if (answer != 0 && answer != 1) {
i = -1;
break;
} else if (answer == 1) {
break;
}
}
printf("%d\n", i);
return 0;
}
#endif
Compilation message (stderr)
game.cpp: In function 'bool dfs(int, int)':
game.cpp:29:18: warning: statement has no effect [-Wunused-value]
29 | #define dbg(...) 1337;
| ^~~~
game.cpp:55:3: note: in expansion of macro 'dbg'
55 | dbg(node,top)
| ^~~
game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:29:18: warning: statement has no effect [-Wunused-value]
29 | #define dbg(...) 1337;
| ^~~~
game.cpp:79:3: note: in expansion of macro 'dbg'
79 | dbg(ok);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |