QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#716200 | #8760. 不等式 | qikala7777# | WA | 2ms | 3856kb | C++23 | 1.3kb | 2024-11-06 14:39:23 | 2024-11-06 14:39:24 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=1e6+7,inf=0x3f3f3f3f;const LL Linf=0x3f3f3f3f3f3f3f3fLL;
LL qsm(LL a,LL b,LL p){LL res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
LL lowbit(LL x){return x&-x;}
int n,m;
vector<int>g[N];
int du[N];
LL res;
int cnt;
bool bfs(){
queue<int>q;
for(int i=1;i<=n;i++)if(!du[i])q.push(i);
unordered_map<int,LL>mp;
while(q.size()){
int len=q.size();
cnt++;
while(len--){
int u=q.front();q.pop();
if(mp.count(u))continue;
mp[u]=cnt;
res=res-1+cnt;
for(auto v:g[u]){
if(--du[v]==0)q.push(v);
}
}
}
for(int i=1;i<=n;i++)if(du[i])return false;
return true;
}
void solve(){
cin>>n>>m;
res=n,cnt=0;
for(int i=1;i<=m;i++){
int x,y,z;
cin>>x>>y>>z;
g[y].push_back(x);
g[z].push_back(x);
du[x]+=2;
}
if(bfs()&&res<=1e9)cout<<res<<endl;
else cout<<-1<<endl;
}
int main(){
IOS
int T=1;
//cin>>T;
while(T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3844kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3664kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3620kb
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: 3632kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 3600kb
input:
10 2 1 2 2 2 3 4
output:
13
result:
wrong answer 1st numbers differ - expected: '14', found: '13'