QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745308#2918. Tree Number GeneratoralexhamidiRE 0ms3496kbC++142.1kb2024-11-14 09:05:132024-11-14 09:05:14

Judging History

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

  • [2024-11-14 09:05:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3496kb
  • [2024-11-14 09:05:13]
  • 提交

answer

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    int digits[n+1];

    string paths[n+1][n+1];
    vector<int> con[n+1];



    for (int i = 0;  i < n-1; i++) {
        int a, b;
        cin >> a >> b;

        for (auto& i : con[a]) {
            if (paths[i][b].empty()) {

                paths[i][b] = paths[i][a];
                paths[i][b] += to_string(b);

                paths[b][i] = to_string(a);
                paths[b][i] += paths[a][i];

                con[i].push_back(b);
                con[b].push_back(i);
            }
        }
        for (auto& i : con[b]) {
            if (paths[i][a].empty()) {

                paths[i][a] = paths[i][b];
                paths[i][a] += to_string(a);

                paths[a][i] = to_string(b);
                paths[a][i] += paths[b][i];

                con[i].push_back(a);
                con[a].push_back(i);
            }
        }

        paths[a][b] = to_string(b);
        paths[b][a] = to_string(a);

        con[b].push_back(a);
        con[a].push_back(b);
    }

    for (int i = 1; i <= n; i++) {
        paths[i][i] = to_string(i);
    }

    for (int i = 1; i <= n; i++) {
        cin >> digits[i];
    }

    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        string path = paths[a][b];
        string num = "";
        for (char c : path) {
            num += digits[c-'0']+'0';
        }

        int res = 0;
        int digits = num.size();
        for (int i = 0; i < digits; i++) {
            int curr = num[i]-'0';
            int factor = stoi("1"+string(digits-i-1, '0'));
            res = (res + (curr % m) * (factor % m)) % m;
        }
        cout << res << "\n";
    }
    return 0;
}

/*

simply simulate. problem - how to find the path to a node

need to be able to do it in logn

only one path - how to get that path?

need to have everything in the path  to get the path



problem reduced to finding
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1 4
1 2
1
3
1 2
2 1
1 1
2 2

output:

0
0
0
0

result:

ok 4 lines

Test #2:

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

input:

3 10 5
1 2
2 3
0
0
0
1 3
3 1
2 2
2 3
2 1

output:

0
0
0
0
0

result:

ok 5 lines

Test #3:

score: -100
Runtime Error

input:

2000 2 2000
937 1471
1672 937
356 1672
976 356
1257 356
1503 1257
783 1503
1783 937
1284 976
1955 1503
802 1257
583 1471
526 356
701 1783
393 1955
307 1955
386 1955
1070 937
1724 802
1397 1724
1140 937
422 526
1941 1955
1638 937
1469 526
1800 526
1035 1800
1009 1140
1195 1800
142 1471
1225 1469
1524...

output:


result: