QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#547991 | #8760. 不等式 | xfs001 | WA | 9ms | 52924kb | C++14 | 964b | 2024-09-05 14:30:19 | 2024-09-05 14:30:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>g[2020000];
int r[2020000],a[2020000];
void dfs(int u,int f){
if(a[u])return;
int x=0;
for(auto v:g[u]){
if(v==f)continue;
dfs(v,u);
x+=a[v];
}
a[u]=x;
}
void solve(){
int n,m;cin>>n>>m;
while(m--){
int x,y,z;cin>>x>>y>>z;
g[x].push_back(y);
g[x].push_back(z);
g[y].push_back(x);
g[z].push_back(x);
r[x]+=2;
}
queue<int>q;
vector<int>res;
for(int i=1;i<=n;i++){
if(r[i]==0){
q.push(i);
a[i]=1;
}
}
while(q.size()){
int p=q.front();q.pop();
res.push_back(p);
for(auto it:g[p]){
r[it]--;
if(r[it]==0)
q.push(it);
}
}
if(res.size()!=n){
cout<<-1<<'\n';
}else{
int ans=0;
dfs(1,-1);
for(int i=1;i<=n;i++)
ans+=a[i];
cout<<ans;
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 51656kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 4ms
memory: 51176kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 4ms
memory: 52084kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 4ms
memory: 51848kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 8ms
memory: 51468kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 8ms
memory: 52396kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 4ms
memory: 52160kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 3ms
memory: 52384kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 3ms
memory: 51880kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 51788kb
input:
5 2 1 2 3 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #11:
score: 0
Accepted
time: 4ms
memory: 52912kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 3ms
memory: 51264kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 3ms
memory: 52924kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 9ms
memory: 52448kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: -100
Wrong Answer
time: 4ms
memory: 51624kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'