#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++){
v[i].pb(i+1);
}
}
bool visited[MAXN];
int top;
bool dfs(int node){
if(visited[node]) return node==top;
visited[node]=true;
for(auto x:v[node]){
if(dfs(x)) return true;
}
return false;
}
int add_teleporter(int a, int b) {
v[a].pb(b);
memset(visited,false,sizeof(visited));
bool ok=false;
for(int i=0;i<k;i++){
memset(visited,false,sizeof(visited));
top=i;
ok|=dfs(i);
if(ok) return true;
}
return false;
return dfs(0);
}
#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
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
22 ms |
1176 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
21 ms |
1112 KB |
Output is correct |
6 |
Correct |
21 ms |
1112 KB |
Output is correct |
7 |
Correct |
22 ms |
1172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
22 ms |
1176 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
21 ms |
1112 KB |
Output is correct |
6 |
Correct |
21 ms |
1112 KB |
Output is correct |
7 |
Correct |
22 ms |
1172 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1112 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
4 ms |
1112 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
9 ms |
1112 KB |
Output is correct |
18 |
Correct |
4 ms |
1112 KB |
Output is correct |
19 |
Correct |
5 ms |
1172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
22 ms |
1176 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
21 ms |
1112 KB |
Output is correct |
6 |
Correct |
21 ms |
1112 KB |
Output is correct |
7 |
Correct |
22 ms |
1172 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1112 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
4 ms |
1112 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
9 ms |
1112 KB |
Output is correct |
18 |
Correct |
4 ms |
1112 KB |
Output is correct |
19 |
Correct |
5 ms |
1172 KB |
Output is correct |
20 |
Correct |
5 ms |
1368 KB |
Output is correct |
21 |
Correct |
10 ms |
1112 KB |
Output is correct |
22 |
Correct |
60 ms |
1184 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
1148 ms |
1200 KB |
Output is correct |
25 |
Correct |
3206 ms |
1700 KB |
Output is correct |
26 |
Correct |
1949 ms |
1432 KB |
Output is correct |
27 |
Execution timed out |
4022 ms |
1196 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
22 ms |
1176 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
21 ms |
1112 KB |
Output is correct |
6 |
Correct |
21 ms |
1112 KB |
Output is correct |
7 |
Correct |
22 ms |
1172 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1112 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
4 ms |
1112 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
9 ms |
1112 KB |
Output is correct |
18 |
Correct |
4 ms |
1112 KB |
Output is correct |
19 |
Correct |
5 ms |
1172 KB |
Output is correct |
20 |
Correct |
5 ms |
1368 KB |
Output is correct |
21 |
Correct |
10 ms |
1112 KB |
Output is correct |
22 |
Correct |
60 ms |
1184 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
1148 ms |
1200 KB |
Output is correct |
25 |
Correct |
3206 ms |
1700 KB |
Output is correct |
26 |
Correct |
1949 ms |
1432 KB |
Output is correct |
27 |
Execution timed out |
4022 ms |
1196 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1112 KB |
Output is correct |
3 |
Correct |
22 ms |
1176 KB |
Output is correct |
4 |
Correct |
4 ms |
1112 KB |
Output is correct |
5 |
Correct |
21 ms |
1112 KB |
Output is correct |
6 |
Correct |
21 ms |
1112 KB |
Output is correct |
7 |
Correct |
22 ms |
1172 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1112 KB |
Output is correct |
10 |
Correct |
1 ms |
1112 KB |
Output is correct |
11 |
Correct |
1 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
1112 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
3 ms |
1112 KB |
Output is correct |
15 |
Correct |
4 ms |
1112 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
9 ms |
1112 KB |
Output is correct |
18 |
Correct |
4 ms |
1112 KB |
Output is correct |
19 |
Correct |
5 ms |
1172 KB |
Output is correct |
20 |
Correct |
5 ms |
1368 KB |
Output is correct |
21 |
Correct |
10 ms |
1112 KB |
Output is correct |
22 |
Correct |
60 ms |
1184 KB |
Output is correct |
23 |
Correct |
5 ms |
1364 KB |
Output is correct |
24 |
Correct |
1148 ms |
1200 KB |
Output is correct |
25 |
Correct |
3206 ms |
1700 KB |
Output is correct |
26 |
Correct |
1949 ms |
1432 KB |
Output is correct |
27 |
Execution timed out |
4022 ms |
1196 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |