QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682690#9246. Dominating PointOldMemory#TL 0ms3628kbC++201.5kb2024-10-27 16:59:022024-10-27 16:59:02

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 18:38:25]
  • hack成功,自动添加数据
  • (/hack/1238)
  • [2024-10-27 16:59:02]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3628kb
  • [2024-10-27 16:59:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
typedef pair<int, int> pll;
typedef long long LL;
const int INF = 0x3f3f3f3f3f3f3f3f, mod = 1e9 + 7;

bool multi = 0;
constexpr int N = 5e3 + 7;
vector<int>edge[N];
void solve() {
    int n;
    cin >> n;
    vector<vector<char>>s(n + 1, vector<char>(n + 1));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> s[i][j];
            if(s[i][j] == '1')edge[i].push_back(j);
        }
    }
    auto bfs = [&](int x) -> bool {
        queue<pll>q;
        vector<bool>vis(n + 1);
        q.push({x, 0});
        vis[x] = 1;
        int tot = 1;
        while(q.size())
        {
            auto [u, d] = q.front();
            q.pop();
            for (auto v : edge[u])
            {
                if(!vis[v])
                {
                    if(d + 1 > 2)return 0;
                    vis[v] = 1;
                    tot++;
                    q.push({v, d + 1});
                }
            }
        }
        if(tot == n)return 1;
        return 0;
    };
    vector<int>ans;
    for (int i = 1; i <= n; i++)
    {
        if(bfs(i))ans.push_back(i);
    }
    if(ans.size() >= 3)
    {
        for (int i = 0; i < 3; i++)cout << ans[i] << " \n"[i == 2];
    }
    else cout << "NOT FOUND" << endl;
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T = 1;
    if(multi) cin >> T;
    while(T--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

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: 3548kb

input:

3
011
001
000

output:

NOT FOUND

result:

ok OK, Answer correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

3
010
001
100

output:

1 2 3

result:

ok OK, Answer correct.

Test #4:

score: -100
Time Limit Exceeded

input:

4994
0100001010011001010101110010101000111101111100100001110010000111100000000100110100101000001010100000010010010110110110111010010010100110100000110110111001010111010111010111011001000101001000010001010111110000000100001100000111100011001010010111011100111010101110011000010111101011111110001111110...

output:


result: