ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#199402 | #2792. emoairx的序列 | tkswls | 100 | 99ms | 2432kb | C++11 | 683b | 2023-12-14 11:34:21 | 2023-12-14 15:59:55 |
answer
#include <bits/stdc++.h>
using namespace std;
int n, m, k, now, a[100005], b[100005], c[100005], d[100005];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
c[i] = i;
}
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i];
}
for (int i = m; i >= 1; i--) {
swap(c[a[i]], c[b[i]]);
}
now = 1;
for (int i = 1; i <= m; i++) {
swap(c[a[i]], c[b[i]]);
if (c[now] == k) {
cout << i;
return 0;
}
if (a[i] == now) now = b[i];
else if (b[i] == now) now = a[i];
}
cout << -1;
}
//10 10 9
//1 8
//8 3
//3 4
//4 7
//7 2
//6 2
//9 10
//3 10
//9 3
//6 9
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
1000 1000 122 750 565 622 451 614 366 49 485 28 903 767 556 876 909 990 430 846 956 925 161 436 738 ...
output:
482
result:
ok single line: '482'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
1000 1000 313 852 12 249 747 153 883 594 458 676 1 644 502 29 445 790 840 620 803 348 274 602 536 64...
output:
1
result:
ok single line: '1'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1280kb
input:
1000 1000 295 801 279 370 382 234 24 296 375 895 340 241 683 826 750 504 373 927 613 955 436 756 389...
output:
1
result:
ok single line: '1'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1284kb
input:
1000 1000 991 330 966 160 412 344 129 312 537 304 292 161 745 896 372 788 824 421 232 148 125 937 96...
output:
532
result:
ok single line: '532'
Test #5:
score: 10
Accepted
time: 17ms
memory: 2428kb
input:
100000 100000 15229 1 6907 6907 23876 23876 20811 20811 23616 23616 32565 32565 8204 8204 24791 2479...
output:
1057
result:
ok single line: '1057'
Test #6:
score: 10
Accepted
time: 17ms
memory: 2428kb
input:
100000 100000 76005 1 27119 27119 13077 13077 11621 11621 32416 32416 17948 17948 2830 2830 17211 17...
output:
10568
result:
ok single line: '10568'
Test #7:
score: 10
Accepted
time: 15ms
memory: 2432kb
input:
100000 100000 6180 1 20994 20994 20232 20232 675 675 4793 4793 8436 8436 15675 15675 19507 19507 251...
output:
30568
result:
ok single line: '30568'
Test #8:
score: 10
Accepted
time: 18ms
memory: 2432kb
input:
100000 100000 6214 7589 1386 31971 4110 6140 29014 12681 27926 25390 28440 1910 13821 32691 11804 76...
output:
87654
result:
ok single line: '87654'
Test #9:
score: 10
Accepted
time: 16ms
memory: 2428kb
input:
100000 100000 12250 19226 2389 13728 23608 1209 6732 16509 7324 20953 29761 10716 18691 10328 7659 2...
output:
97654
result:
ok single line: '97654'
Test #10:
score: 10
Accepted
time: 16ms
memory: 2424kb
input:
100000 100000 88111 4220 29005 6431 5192 5790 4373 18040 31851 19178 30290 14239 20639 14490 19108 1...
output:
1
result:
ok single line: '1'