QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#587897 | #6705. Median | zzz666 | WA | 5ms | 3792kb | C++20 | 1.2kb | 2024-09-24 22:23:26 | 2024-09-24 22:23:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
void slove()
{
int ans;
int indegree[N]={0};
int outdegree[N]={0};
queue <int> q;
vector<int>a[N];
int n,m;
cin >> n>>m;
for (int i = 1; i <= m; i++) //存图
{
int x,y;
cin>>x>>y;
a[x].push_back(y);
// a[y].push_back(x);
indegree[y]++;
outdegree[x]++;
}
/* for(int i = 1 ; i <=n ; i++ )
{
cout<<indegree[i]<<" ";
}
cout<<endl;
for(int i = 1 ; i <=n ; i++ )
{
cout<<outdegree[i]<<" ";
}
cout<<endl;
cout<<endl;*/
for(int i = 1 ; i <=n ; i++ )
{
if(indegree[i]==outdegree[i])
{
ans = i ;
break;
}
}
for (int i = 1; i <= n; i++)
{
if (indegree[i] == 0) q.push(i);
}
while(!q.empty())
{
int x = q.front(); q.pop();
for (int i = 0; i < a[x].size(); i++)
{
int t = a[x][i];
indegree[t]--;
if (indegree[t]==0)
q.push(t);
}
}
for(int i = 1 ; i <=n ; i++ )
{
if(indegree[i]!=0)
{
for(int i = 1 ; i <= n ; i++)
cout<<'0';
return;
}
}
for(int i = 1; i <= n ; i++ )
{
if(i==ans) cout<<'1';
else cout<<'0';
}
}
int main()
{
int tcase;
cin>>tcase;
while(tcase--)
{
slove();
cout<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
2 5 4 1 2 3 2 2 4 2 5 3 2 1 1 2 3
output:
01000 000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 3576kb
input:
66 13 2 9 13 7 11 11 19 9 1 8 1 5 1 2 8 4 2 2 1 5 2 6 3 3 11 3 2 4 6 6 10 9 8 3 5 1 7 5 8 3 9 4 9 6 7 3 1 2 3 11 6 9 4 1 6 5 2 1 5 4 6 8 4 15 15 10 6 15 8 7 6 11 1 5 2 3 4 11 13 4 6 10 12 10 13 1 6 15 2 5 12 13 14 5 3 15 86 14 12 8 1 14 9 8 15 5 10 1 9 11 2 6 2 7 10 10 13 14 5 4 13 5 8 4 10 13 9 6 9...
output:
1000000000000 00000000100 100 00100000000 100000000000000 000000000000001 00100 01000 0100000 0000000000100 100000000 100000000 100000000000000 000010000 000010000 0000000000001 0100000000000 000000000010000 00000000001 000000000010000 00000001000 00100000000 00010 01000000000 00001000000 00000 0100...
result:
wrong answer 1st lines differ - expected: '1111111111111', found: '1000000000000'