結果
| 問題 |
No.429 CupShuffle
|
| コンテスト | |
| ユーザー |
crazybbb3
|
| 提出日時 | 2016-10-29 14:37:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 349 ms / 2,000 ms |
| コード長 | 4,030 bytes |
| コンパイル時間 | 2,800 ms |
| コンパイル使用メモリ | 83,328 KB |
| 実行使用メモリ | 61,680 KB |
| 最終ジャッジ日時 | 2024-11-24 17:57:10 |
| 合計ジャッジ時間 | 6,683 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
void solve() throws IOException {
int n = ni();
int k = ni();
int x = ni();
int[] a = new int[k];
int[] b = new int[k];
for (int i = 0; i < k; i++) {
if (i != x - 1) {
a[i] = ni() - 1;
b[i] = ni() - 1;
} else {
in.readLine();
}
}
int[] c = nia(n);
int[] d = new int[n];
for (int i = 0; i < n; i++) {
d[i] = i + 1;
}
for (int i = 0; i < x - 1; i++) {
int tmp = d[a[i]];
d[a[i]] = d[b[i]];
d[b[i]] = tmp;
}
for (int i = k - 1; i >= x; i--) {
int tmp = c[a[i]];
c[a[i]] = c[b[i]];
c[b[i]] = tmp;
}
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (c[i] != d[i]) {
list.add(i + 1);
}
}
Collections.sort(list);
out.println(list.get(0) + " " + list.get(1));
}
void output(int x, int y) {
String ans = "";
if (x < 0) {
for (int i = 0; i < y; i++) {
if (i == 0) ans += "w";
else ans += "wC";
}
for (int i = 0; i < x; i++) {
ans += "cW";
}
} else if (y < 0) {
for (int i = 0; i < x; i++) {
if (i == 0) ans += "c";
else ans += "cC";
}
for (int i = 0; i < x; i++) {
ans += "wW";
}
} else {
for (int i = 0; i < y; i++) {
if (i == 0) ans += "c";
else ans += "cC";
}
for (int i = 0; i < x; i++) {
if ("".equals(ans)) ans += "w";
ans += "wC";
}
}
out.println(ans);
}
int gcd(int a, int b) {
return a == 0 ? b : gcd(b % a, a);
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int[] extgcd(int a, int b, int[] is) {
if (a == 0) {
is[0] = 0;
is[1] = 1;
is[2] = b;
} else {
extgcd(b % a, a, is);
int x = is[1] - b / a * is[0];
is[1] = is[0];
is[0] = x;
}
return is;
}
String ns() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine(), " ");
}
return tok.nextToken();
}
int ni() throws IOException {
return Integer.parseInt(ns());
}
long nl() throws IOException {
return Long.parseLong(ns());
}
double nd() throws IOException {
return Double.parseDouble(ns());
}
String[] nsa(int n) throws IOException {
String[] res = new String[n];
for (int i = 0; i < n; i++) {
res[i] = ns();
}
return res;
}
int[] nia(int n) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = ni();
}
return res;
}
long[] nla(int n) throws IOException {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nl();
}
return res;
}
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
tok = new StringTokenizer("");
Main main = new Main();
main.solve();
out.close();
}
}
crazybbb3