QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669754 | #8760. 不等式 | zwu2021016689 | WA | 0ms | 12052kb | C++17 | 1008b | 2024-10-23 19:34:14 | 2024-10-23 19:34:15 |
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]){
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];
}
}
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
*/
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: 0
Wrong Answer
time: 0ms
memory: 12052kb
input:
3 1 1 2 2
output:
-1
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'