QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408464#6772. Spicy RestaurantChongQYTL 40ms73648kbJava85.1kb2024-05-10 13:03:512024-05-10 13:03:52

Judging History

你现在查看的是最新测评结果

  • [2024-05-10 13:03:52]
  • 评测
  • 测评结果:TL
  • 用时:40ms
  • 内存:73648kb
  • [2024-05-10 13:03:51]
  • 提交

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 int MID = (int) (1 * 1e5 + 7);
    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 int[] arr = new int[MID];
//    public static long[] Qz = new long[MID];
//    public static long[] Hz = 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 int[][] va = new int[MID][105];
    public static boolean[] pool = new boolean[MID];
    public static void solve(){
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int q = scanner.nextInt();
        int min = IMAX;
        for(int i = 0 ; i <= n ; i++) list[i] = new ArrayList<>();
        for(int i = 1 ; i <= n ; i++) {arr[i] = scanner.nextInt();min = Math.min(min , arr[i]);}
        for(int i = 1 ; i <= m ; i++){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            list[a].add(b);
            list[b].add(a);
        }
        for(int i = 1 ; i <= n ; i++){//以每个点位起点
            for(int j = 1 ; j <= 100 ; j++){// 最大承受
                if(j < min){va[i][j] = -1;continue;}
                if(j >= arr[i]){
                    va[i][j] = 0;
                } else {
                    Arrays.fill(pool , 1 , n  + 1 , false);
                    int o = bfs(j , i);
                    va[i][j] = o;
                }
            }

        }
        for(int i = 1 ; i <= q ; i++){
            int pi = scanner.nextInt();
            int ai = scanner.nextInt();
            out.println(va[pi][ai]);
        }


    }
    public static int bfs(int max , int sta){
        pool[sta] = true;
        Queue<way> queue = new ArrayDeque<>();
        queue.add(new way(sta , 0));
        while(!queue.isEmpty()){
            way w = queue.poll();
            int in = w.iq;
            int cnt = w.cnt;
            for(Integer i : list[in]){
                if(pool[i]) continue;
                if(arr[i] <= max) return cnt + 1;
                pool[i] = true;
                queue.add(new way(i , cnt + 1));
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int T = 1;
//        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: 100
Accepted
time: 40ms
memory: 73648kb

input:

4 4 5
5 4 2 3
1 2
2 3
3 4
4 1
1 1
1 2
1 3
1 4
1 5

output:

-1
2
1
1
0

result:

ok 5 lines

Test #2:

score: -100
Time Limit Exceeded

input:

50000 100000 100000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ...

output:


result: