QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#318162 | #4584. Not One | ouo# | WA | 65ms | 9988kb | C++17 | 1.3kb | 2024-01-30 16:42:14 | 2024-01-30 16:42:14 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ssuyu \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>
#define int long long
#define PI acos(-1)
#define all(x) (x).begin(), (x).end()
const int N = 1e5 + 5;
int vis[N];
vector<int> v[N];
int bfs(int x) {
int cnt = 0;
queue<int> q;
q.push(x);
while (!q.empty()) {
cnt++;
x = q.front();
vis[x] = 1;
q.pop();
for (auto u : v[x]) {
if (!vis[u])
q.push(u);
}
}
return cnt;
}
signed main() {
int n, m, x, y;
char c;
string str[105];
int mx = 0, ans = 0;
map<char, int> mp;
int a[N];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
cin >> x >> y;
if (__gcd(a[x], a[y]) > 1) {
v[x].pb(y);
v[y].pb(x);
}
}
for (int i = 1; i < n; i++) {
if (!vis[N] && a[i] > 1)
mx = max(bfs(i), mx);
}
cout << mx;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 6916kb
input:
7 10 5 8 6 10 6 4 1 2 2 3 2 4 4 5 4 6 4 7
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7276kb
input:
4 1 1 1 1 1 2 2 3 3 4
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 6692kb
input:
5 100 100 100 100 100 3 4 1 2 3 5 2 4
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6984kb
input:
2 1 1 1 2
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 65ms
memory: 9988kb
input:
100000 860163 795323 862289 543383 792647 337047 353985 959953 874318 573652 69827 958063 571741 704399 311826 920477 792478 151531 872269 592307 853819 865817 940735 620657 937154 696551 749279 552523 836161 707467 389626 459089 563763 668884 810391 639709 419361 580342 519595 836124 494959 669379 ...
output:
524
result:
wrong answer 1st lines differ - expected: '213', found: '524'