QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#724381 | #9246. Dominating Point | yld | TL | 0ms | 3624kb | C++20 | 1.5kb | 2024-11-08 12:48:54 | 2024-11-08 12:48:54 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
void solve()
{
int n;cin>>n;
vector<int> e[n+1];
for(int i=1;i<=n;i++)
{
string s;cin>>s;
s=' '+s;
for(int j=1;j<=n;j++)
if(s[j]=='1')e[i].push_back(j);
}
// for(int i=1;i<=n;i++)
// for(auto v:e[i]) cout<<i<<' '<<v<<endl;
vector<vector<int>> vis(n+1,vector<int>(3));
function<void(int,int)> dfs=[&](int u,int dep)
{
// cout<<u<<' '<<dep<<endl;
vis[u][dep]=1;
if(dep==2) return;
for(auto v:e[u])
{
if(vis[v][1]) continue;
dfs(v,dep+1);
}
};
// vis[3][1]=vis[3][2]=1;
// dfs(3,0);
// cout<<"========\n";
// for(int i=1;i<=n;i++) cout<<vis[i][1]<<' '<<vis[i][2]<<endl;
vector<int> ans;
for(int i=1;i<=n;i++)
{
// cout<<"============\n";
for(int i=1;i<=n;i++) vis[i][0]=vis[i][1]=vis[i][2]=0;
vis[i][1]=vis[i][2]=1;
dfs(i,0);
int tmp=0;
for(int j=1;j<=n;j++)
if(!vis[j][1] && !vis[j][2]) tmp=1;
if(!tmp) ans.push_back(i);
// if(i==3)
// {
// for(int j=1;j<=n;j++) cout<<vis[j][1]<<' '<<vis[j][2]<<endl;
// }
}
if(ans.size()<3) cout<<"NOT FOUND";
else for(int i=0;i<3;i++) cout<<ans[i]<<' ';
cout<<endl;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t=1;
while(t--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
6 011010 000101 010111 100001 010100 100010
output:
1 3 4
result:
ok OK, Answer correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 011 001 000
output:
NOT FOUND
result:
ok OK, Answer correct.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 010 001 100
output:
1 2 3
result:
ok OK, Answer correct.
Test #4:
score: -100
Time Limit Exceeded
input:
4994 0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...