QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#411372 | #6765. Don't Really Like How The Story Ends | ChongQY | WA | 46ms | 29440kb | Java8 | 5.2kb | 2024-05-15 12:18:08 | 2024-05-15 12:18:10 |
Judging History
answer
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static Read scanner = new Read(System.in);
// public static final long MOD = (long) (1e9 + 7);
public static final long MOD = 998244353;
public static final int MID = (int) (1 * 1e5 + 100);
public static final long LMAX = Long.MAX_VALUE;
public static final long LMIN = Long.MIN_VALUE;
public static final int IMAX = Integer.MAX_VALUE;
public static final int IMIN = Integer.MIN_VALUE;
public static long[] arr = new long[MID];
// public static long[] Q = new long[MID];
// public static long[] H = new long[MID];
public static int N, M , n , m;
public static long ans;
// public static boolean[][] stack = new boolean[MID][MID];
//四个方向
public static int[] row = {1, -1, 0, 0};
public static int[] cos = {0, 0, 1, -1};
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static ArrayList<Integer>[] list = new ArrayList[MID];
public static HashSet<Integer>[] sets = new HashSet[MID];
public static boolean[] pool = new boolean[MID];
public static int iq = 1;
public static void solve(){
n = scanner.nextInt();
int m = scanner.nextInt();
for(int i = 0 ; i <= n + 10 ; i++) {
list[i] = new ArrayList<>();
sets[i] = new HashSet<>();
pool[i] = false;
}
for(int i = 1 ; i <= m ; i++){
int a = scanner.nextInt();
int b = scanner.nextInt();
if(a == b) continue;
if(a > b){
list[a].add(b);
sets[a].add(b);
} else {
list[b].add(a);
sets[b].add(a);
}
}
if(n == 1){
out.println(0);
return;
}
iq = 1;
ans = 0;
dfs(1);
out.println(Math.max(0 , ans));
/*
3
2 3
1 1
1 2
2 1
4 1
1 4
4 2
1 2
3 4
*/
/*
3 7
2 1
3 3
1 3
1 1
3 2
1 1
3 1
4 8
2 3
4 3
3 2
4 2
1 3
2 1
4 3
2 4
*/
}
public static void dfs(int in){
if(iq > n) return;
pool[in] = true;
if(pool[iq]) iq++;
for(Integer i : list[in]){
if(i < iq) continue;
if(pool[i]) continue;
if(i == iq){
dfs(i);
} else {
if(sets[in].contains(iq)){
dfs(iq);
} else {
while(!sets[in].contains(iq)){
ans++;
dfs(iq);
}
dfs(iq);
}
}
}
while(in == 1 && iq <= n){
ans++;
dfs(iq);
}
}
public static void main(String[] args) {
int T = scanner.nextInt();
// long start = System.currentTimeMillis();//程序开始时间戳
while (T-- != 0) {
solve();
}
out.flush();
// long end = System.currentTimeMillis();//程序结束时间戳
// out.println("运行时间 : " + (end - start));//输出运行时间
}
//快读
static class Read {
BufferedReader br;
StringTokenizer st;
public Read(InputStream in) {
br = new BufferedReader(new InputStreamReader(in), 16384);
eat("");
}
public void eat(String s) {
st = new StringTokenizer(s);
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
System.out.println(" ");
return null;
}
}
public boolean hasNext() {
while (!st.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}
public String next() {
hasNext();
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
public BigDecimal nextBigDecimal() {
return new BigDecimal(next());
}
}
public static void swap(long[] arr , int index1 , int index2){
long t = arr[index1];
arr[index1] = arr[index2];
arr[index2] = t;
}
public static long Dot_pitch(long x , long y , long xx , long yy){
return (xx - x) * (xx - x) + (yy - y) * (yy - y);
// return (long) Math.sqrt(Math.pow(xx - x , 2) + Math.pow(yy - y , 2));
}
}
class way {
public int iq ,cnt;
public way(int iq , int cnt) {
this.iq = iq;
this.cnt = cnt;
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 46ms
memory: 29440kb
input:
3 2 3 1 1 1 2 2 1 4 1 1 4 4 2 1 2 3 4
output:
1 3 3
result:
wrong answer 1st lines differ - expected: '0', found: '1'