QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572314 | #9319. Bull Farm | wenqizhi | WA | 1ms | 5968kb | C++17 | 3.4kb | 2024-09-18 13:39:27 | 2024-09-18 13:39:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int read()
{
int x = 0; bool f = false; char c = getchar();
while(c < '0' || c > '9') f |= (c == '-'), c = getchar();
while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c & 15), c = getchar();
return f ? -x : x;
}
const int inf = 0x7fffffff;
const int N = 4005;
int n, L, Q;
int vis[N];
char s[N];
int f[N];
int find(int x){ return (x == f[x]) ? (f[x]) : (f[x] = find(f[x])); }
void merge(int x, int y)
{
x = find(x), y = find(y);
if(x == y) return ;
f[y] = x;
}
vector< pair<int, int> > V[N];
priority_queue< pair<int, int> > q;
int dis[2005][2005], Vis[2005];
void dijkstra(int S)
{
for(int i = 1; i <= n; ++i) dis[S][i] = inf, Vis[i] = 0;
dis[S][S] = 0;
q.push(pair<int, int>(0, S));
while(!q.empty())
{
int now = q.top().second ;
q.pop();
if(Vis[now]) continue;
Vis[now] = 1;
for(auto [v, w] : V[now])
{
if(dis[S][v] > max(dis[S][now], w))
{
dis[S][v] = max(dis[S][now], w);
q.push(pair<int, int>(-dis[S][v], v));
}
}
}
// printf("S = %d\n", S);
// for(int i = 1; i <= n; ++i) printf("%d ", dis[S][i]);
// printf("\n");
}
void solve()
{
n = read(), L = read(), Q = read();
for(int i = 1; i <= n; ++i) f[i] = i, V[i].clear();
for(int i = 1; i <= L; ++i)
{
for(int j = 1; j <= n; ++j) vis[j] = 0;
int cnt = 0;
scanf("%s", s + 1);
for(int j = 1; j <= (n << 1); j += 2)
{
int id = (s[j] - 48) * 50 + (s[j + 1] - 48);
if(!vis[id]) ++cnt, ++vis[id];
}
// printf("cnt = %d\n", cnt);
if(cnt <= n - 2) continue;
if(cnt == n)
{
for(int j = 1; j <= (n << 1); j += 2)
{
int id = (s[j] - 48) * 50 + (s[j + 1] - 48);
if(find((j + 1) >> 1) == find(id)) continue;
merge(find((j + 1) >> 1), find(id));
// printf("双向边:u = %d, v = %d\n", (j + 1) >> 1, id);
V[((j + 1) >> 1)].emplace_back(pair<int, int>(id, i));
V[id].emplace_back(pair<int, int>(((j + 1) >> 1), i));
}
}else
{
int flag = 0;
for(int j = 1; j <= n; ++j) if(vis[j] == 2){ flag = j; break; }
for(int j = 1; j <= (n << 1); j += 2)
{
int id = (s[j] - 48) * 50 + (s[j + 1] - 48);
if(flag == id)
{
if(find(flag) == find((j + 1) >> 1)) continue;
// printf("单向边:u = %d, v = %d\n", (j + 1) >> 1, id);
V[(j + 1) >> 1].emplace_back(pair<int, int>(flag, i));
}
}
}
}
for(int i = 1; i <= n; ++i) dijkstra(i);
while(Q--)
{
scanf("%s", s + 1);
int a = (s[1] - 48) * 50 + (s[2] - 48), b = (s[3] - 48) * 50 + (s[4] - 48), c = (s[5] - 48) * 50 + (s[6] - 48);
// printf("a = %d, b = %d, c = %d, dis = %d\n", a, b, c, dis[a][b]);
if(dis[a][b] > c) printf("0");
else printf("1");
}
printf("\n");
}
int main()
{
int T = read();
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5968kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3920kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
000100
result:
wrong answer 1st lines differ - expected: '010101', found: '000100'