QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408560 | #6772. Spicy Restaurant | ChongQY | TL | 963ms | 226840kb | Java8 | 5.1kb | 2024-05-10 17:48:12 | 2024-05-10 17:48:14 |
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 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(){
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 = 0 ; i <= n ; i++) Arrays.fill(va[i] , IMAX);
for(int i = 1 ; i <= 100 ; i++){
Arrays.fill(pool , 1 , n + 1 , false);
bfs(i);
}
for(int i = 1 ; i <= q ; i++){
int pi = scanner.nextInt();
int ai = scanner.nextInt();
ans = IMAX;
for(int j = 0 ; j <= ai ; j++) ans = Math.min(ans , va[pi][j]);
if(ans == IMAX){
out.println(-1);
} else {
out.println(ans);
}
}
}
public static void bfs(int o){
Queue<way> queue = new ArrayDeque<>();
for(int i = 1 ; i <= n ; i++){
if(arr[i] == o) {
queue.add(new way(i , 0));
va[i][o] = 0;
pool[i] = true;
}
}
while(!queue.isEmpty()){
way w = queue.poll();
int in = w.iq;
int cnt = w.cnt + 1;
for(Integer i : list[in]){
if(pool[i]) continue;
va[i][o] = Math.min(va[i][o] , cnt);
pool[i] = true;
queue.add(new way(i , cnt));
}
}
}
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;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 38ms
memory: 72116kb
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: 0
Accepted
time: 492ms
memory: 153888kb
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:
0 8 6 5 -1 7 5 5 -1 7 7 6 6 4 6 6 8 5 7 6 8 5 6 7 5 8 7 6 7 6 6 7 5 6 -1 0 6 7 7 -1 7 7 8 -1 7 6 7 0 7 7 8 7 6 7 5 6 8 7 8 7 7 6 -1 6 6 7 7 9 7 6 6 7 6 6 7 7 7 7 7 8 7 -1 6 5 7 6 8 8 7 8 6 7 0 6 -1 7 7 8 8 -1 7 6 6 6 8 6 4 8 5 6 6 8 9 6 8 -1 5 -1 7 7 5 7 6 -1 8 -1 8 8 7 7 0 6 8 6 8 6 6 0 6 8 -1 6 8 ...
result:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 533ms
memory: 159696kb
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:
5 5 6 7 6 7 6 6 5 7 6 4 5 6 7 5 6 8 7 7 7 5 5 5 6 8 6 6 6 7 7 6 6 7 4 5 7 6 6 7 7 6 6 6 6 5 6 3 8 7 6 4 7 5 6 7 6 7 7 7 7 6 6 5 6 7 5 7 6 6 6 7 7 6 6 5 7 7 5 7 5 7 7 7 7 7 7 6 6 6 7 6 5 5 7 6 6 7 6 7 6 6 8 7 7 7 7 8 8 6 7 8 6 5 6 7 6 6 3 6 7 7 6 7 5 7 6 6 6 6 6 6 6 7 7 7 6 7 6 8 7 6 4 7 6 7 6 5 7 7 ...
result:
ok 100000 lines
Test #4:
score: 0
Accepted
time: 500ms
memory: 153928kb
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:
7 8 7 8 5 5 -1 7 7 -1 6 -1 7 7 5 8 7 6 7 8 7 7 8 5 7 7 5 7 7 6 7 7 7 6 5 8 6 5 -1 7 7 6 8 6 -1 8 5 6 7 8 7 8 9 7 -1 7 7 7 5 8 8 7 6 8 6 8 8 6 -1 6 6 -1 6 7 6 7 8 5 5 7 8 8 6 7 -1 7 6 6 6 6 6 6 7 -1 9 6 6 8 9 7 6 7 8 7 7 7 8 7 6 8 8 7 7 -1 5 7 7 8 -1 6 5 6 7 7 8 8 9 7 7 7 -1 7 5 6 -1 6 -1 5 7 7 8 8 6...
result:
ok 100000 lines
Test #5:
score: 0
Accepted
time: 597ms
memory: 160936kb
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:
17230 17229 17231 17231 17233 17231 17231 17232 17229 17229 17229 17230 17230 17230 17230 17229 17230 17233 17229 17228 17233 17231 17229 17231 17229 17231 17228 17231 17231 17230 17230 17230 17230 17231 17230 -1 17232 17228 17230 17228 17231 17229 17230 17229 17229 17230 17233 17230 17231 17229 0 1...
result:
ok 100000 lines
Test #6:
score: 0
Accepted
time: 390ms
memory: 135164kb
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:
17230 17228 17230 17229 17229 17230 17229 17228 17230 17229 17230 17230 17229 17230 17230 17229 17229 17229 17230 17230 17229 17230 17230 17229 17228 17229 17231 17229 17230 17228 17230 17228 17231 17230 17230 17229 17230 17225 17228 17230 17229 17229 17228 17230 17230 17228 17230 17230 17229 17230 ...
result:
ok 100000 lines
Test #7:
score: 0
Accepted
time: 439ms
memory: 143576kb
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:
17229 17228 17230 17228 17227 17228 17228 17229 17229 17227 17229 17229 17229 17226 17228 17228 17226 17228 17228 17229 17228 17229 17228 17229 17228 17227 17228 17229 17228 17226 17229 17228 17229 17228 17227 17228 17229 17229 17228 17228 17228 0 17228 17227 17229 17228 17227 17228 17229 17230 1722...
result:
ok 100000 lines
Test #8:
score: 0
Accepted
time: 952ms
memory: 226488kb
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:
16239 16241 16240 16240 16239 16240 16241 16239 16240 16237 16239 16239 16239 16240 16242 16239 16239 16239 16239 16238 16240 16242 16240 16240 16240 16237 16240 16240 16239 16239 0 16240 0 16238 16239 16238 16239 16240 16239 16239 16239 16238 16239 16240 16239 16240 16239 16239 16242 16238 16238 16...
result:
ok 100000 lines
Test #9:
score: 0
Accepted
time: 963ms
memory: 226840kb
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:
16239 16245 16239 16300 16239 16245 16303 16245 16244 16239 16245 16245 16245 16335 16239 16244 16240 16244 16240 16244 16246 16242 16244 16245 16245 16245 16246 16246 16245 16241 16238 16280 16240 16244 16243 16242 16238 16238 16244 16243 0 16244 16245 16239 16239 16245 16238 16240 16243 16238 1630...
result:
ok 100000 lines
Test #10:
score: 0
Accepted
time: 961ms
memory: 223680kb
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:
16238 16239 16239 16239 16240 16240 16239 16240 16240 16240 16241 16240 16294 16240 16255 16239 16240 16239 16239 16241 16240 16239 16240 16239 16281 16293 16240 16239 16238 16238 16239 16240 16240 16239 16238 16240 16240 16240 16295 16239 16238 16281 16239 16240 16240 16238 16240 16240 16237 16294 ...
result:
ok 100000 lines
Test #11:
score: -100
Time Limit Exceeded
input:
50000 100000 500000 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:
2 3 5 4 5 5 5 4 4 4 5 5 3 3 4 4 4 2 4 5 4 3 1 4 6 3 4 6 3 4 5 4 5 3 4 4 2 5 5 4 4 3 2 3 4 4 3 5 5 4 5 5 4 4 5 3 2 4 5 4 3 3 7 4 2 2 4 4 5 3 4 6 5 5 4 5 4 4 4 4 5 3 4 3 3 4 3 5 4 4 6 3 5 5 5 5 4 6 3 4 4 5 4 5 4 0 4 5 4 3 4 4 4 5 4 4 4 2 4 3 4 2 3 4 5 2 4 5 4 4 1 5 3 0 4 4 5 5 4 4 5 3 3 4 3 5 3 5 4 3 ...