QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485236 | #8593. Coin | Issa | 0 | 2ms | 5920kb | C++20 | 1015b | 2024-07-20 15:20:00 | 2024-07-20 15:20:00 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 1e6 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 26;
const int P = 31;
int n, m;
vector<int> g[maxn];
int cnt[maxn];
int ans[maxn];
void test(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
g[a].push_back(b); cnt[b]++;
}
vector<int> cur;
for(int i = 1; i <= n; i++){
if(!cnt[i]) cur.push_back(i);
ans[i] = -1;
}
while(cur.size()){
if(cur.size() == 1) ans[cur[0]] = 1;
vector<int> nxt;
for(int v: cur){
for(int to: g[v]){
cnt[to]--;
if(!cnt[to]) nxt.push_back(to);
}
}
cur = nxt;
}
for(int i = 1; i <= n; i++){
cout << ans[i] << ' ';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; t = 1;
while(t--) test();
cout << ent;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Acceptable Answer
time: 2ms
memory: 5920kb
input:
4 4 2 4 3 1 4 1 2 3
output:
1 1 -1 -1
result:
points 0.50 -1 correct
Test #2:
score: 3
Acceptable Answer
time: 2ms
memory: 5876kb
input:
6 8 1 5 5 4 6 2 2 5 4 3 6 1 6 5 2 1
output:
1 1 1 1 1 1
result:
points 0.50 -1 correct
Test #3:
score: 6
Accepted
time: 2ms
memory: 5876kb
input:
2 1 1 2
output:
1 1
result:
ok ac
Test #4:
score: 0
Wrong Answer
time: 2ms
memory: 5716kb
input:
6 12 1 5 5 4 6 2 2 5 4 3 6 5 1 5 1 5 2 4 6 3 1 3 4 3
output:
-1 1 1 1 1 -1
result:
wrong answer wa
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%