QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#519750 | #8760. 不等式 | Xiao_Shuai_Ge | WA | 2ms | 10676kb | C++14 | 874b | 2024-08-15 00:59:57 | 2024-08-15 00:59:57 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int>g[200005];
queue<int>q;
int a[200005]={0};
int b[200005]={0};
int d[200005]={0};
ll res=0;
void dfs(int u,int v) {
if (d[u]<v) {
res+=v-d[u];
d[u]=v;
for (auto x:g[u]) {
dfs(x,v+1);
}
}
}
int main()
{
int n,m;
cin>>n>>m;
int x,y,z;
while (m--) {
cin>>x>>y>>z;
a[x]+=2,b[x]+=2;
g[y].push_back(x);
g[z].push_back(x);
}
for (int i=1;i<=n;i++) {
if (a[i]==0) {
q.push(i);
}
}
while (!q.empty()) {
for (auto x:g[q.front()]) {
a[x]--;
if (a[x]==0) {
q.push(x);
}
}
q.pop();
}
for (int i=1;i<=n;i++) {
if (a[i]) {
cout<<-1<<endl;
return 0;
}
}
for (int i=1;i<=n;i++) {
if (b[i]==0 && d[i]==0) {
dfs(i,1);
}
//cout<<d[i]<<endl;
}
cout<<res<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9196kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 10268kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 2ms
memory: 8988kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 2ms
memory: 10420kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 2ms
memory: 9704kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 2ms
memory: 9300kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 9968kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 2ms
memory: 9556kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 2ms
memory: 9312kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 10520kb
input:
5 2 1 2 3 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #11:
score: 0
Accepted
time: 1ms
memory: 10676kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 1ms
memory: 8800kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 1ms
memory: 8924kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: -100
Wrong Answer
time: 0ms
memory: 10168kb
input:
10 2 1 2 2 2 3 4
output:
13
result:
wrong answer 1st numbers differ - expected: '14', found: '13'