QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669774 | #8760. 不等式 | zwu2021016689 | WA | 2ms | 12356kb | C++17 | 1.0kb | 2024-10-23 19:37:59 | 2024-10-23 19:38:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dg(x) cout<<#x<<'='<<x<<'\n';
const int N=2e5+10;
vector<int>g[N];
int vis[N],dis[N],in[N];
int co=0;
int ans=0;
int root;
set<int>s;
void dfs(int x){
//dg(x)
if(co==1) return ;
if(s.find(x)!=s.end()){
co=1;
return ;
}
s.insert(x);
if(vis[x]){
s.erase(x);
return ;
}
vis[x]=1;
for(auto u:g[x]){
dfs(u);
}
if(g[x].size()==0){
dis[x]=1;
}
else{
for(auto u:g[x]) dis[x]+=dis[u];
}
s.erase(x);
}
inline void solve()
{
int n,m;
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);
}
for(int i=1;i<=n;i++){
if(vis[i]) continue;
dfs(i);
s.clear();
}
for(int i=1;i<=n;i++) ans+=dis[i];
if(co) ans=-1;
cout<<ans<<'\n';
}
/*
5 2
1 2 3
3 1 2
6 3
1 2 3
3 4 5
6 3 5
3 1
1 2 2
*/
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12200kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9544kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 10804kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9300kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 1ms
memory: 10928kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 2ms
memory: 12160kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 2ms
memory: 10988kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 2ms
memory: 9740kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 12092kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 1ms
memory: 8988kb
input:
5 2 1 2 3 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #11:
score: 0
Accepted
time: 2ms
memory: 12356kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 9152kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 2ms
memory: 10824kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 1ms
memory: 10708kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: -100
Wrong Answer
time: 1ms
memory: 9324kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'