QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604603 | #8760. 不等式 | xing4c# | WA | 2ms | 8844kb | C++14 | 1.4kb | 2024-10-02 12:25:32 | 2024-10-02 12:25:32 |
Judging History
answer
#include <bits/stdc++.h>
#define NOSYNC ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int N = 200005;
// -------------- Templates Above -------------------------
int a[N]; int n, m;
vector<int> G[N];
int in[N]; int vis[N]; int d[N];
void dfs1(int x) {
// cout << "dfs1: " << x << endl;
vis[x] = 1;
if(vis[x]) return;
if(G[x].empty()) {
a[x] = 1;
return;
}
priority_queue<int> q;
for(int y : G[x]) {
dfs1(y);
q.push(a[y]);
}
int v1 = q.top(); q.pop();
int v2 = q.top(); q.pop();
a[x] = v1 + v2;
}
signed main() {
NOSYNC;
cin >> n >> m;
for(int i = 1; i <= m; i ++) {
int x, y, z;
cin >> x >> y >> z;
G[x].push_back(y);
G[x].push_back(z);
++ in[y]; ++ in[z];
++ d[y]; ++ d[z];
}
queue<int> q;
for(int i = 1; i <= n; i ++) {
if(!d[i]) {
q.push(i);
}
}
while(!q.empty()) {
int u = q.front(); q.pop();
vis[u] = 1;
for(int v : G[u]) {
-- d[v];
if(!d[v]) {
q.push(v);
}
}
}
for(int i = 1; i <= n; i ++) {
if(!vis[i]) {
cout << -1 << endl;
return 0;
}
}
for(int i = 1; i <= n; i ++) vis[i] = 0;
for(int i = 1; i <= n; i ++) {
if(!in[i] && !vis[i]) dfs1(i);
}
int ans = 0;
for(int i = 1; i <= n; i ++) {
ans += a[i];
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8844kb
input:
3 1 1 2 2
output:
0
result:
wrong answer 1st numbers differ - expected: '4', found: '0'